Незначительные исправления

This commit is contained in:
Victor 2018-10-19 16:10:29 +03:00
parent 670b4b8718
commit be9bdb0311
10 changed files with 33 additions and 22 deletions

View File

@ -1,6 +1,8 @@
# OwnLang # OwnLang
[![Build Status](https://travis-ci.org/aNNiMON/Own-Programming-Language-Tutorial.svg?branch=latest)](https://travis-ci.org/aNNiMON/Own-Programming-Language-Tutorial) [![Build Status](https://travis-ci.org/aNNiMON/Own-Programming-Language-Tutorial.svg?branch=latest)](https://travis-ci.org/aNNiMON/Own-Programming-Language-Tutorial)
[![SonarCloud Status](https://sonarcloud.io/api/project_badges/measure?project=aNNiMON_Own-Programming-Language-Tutorial&metric=alert_status)](https://sonarcloud.io/dashboard?id=aNNiMON_Own-Programming-Language-Tutorial)
[![SonarCloud Quality Gate](https://sonarcloud.io/api/project_badges/measure?project=aNNiMON_Own-Programming-Language-Tutorial&metric=sqale_rating)](https://sonarcloud.io/dashboard/?id=aNNiMON_Own-Programming-Language-Tutorial)
| Free | Pro | Desktop | | Free | Pro | Desktop |
| :--: | :-: | :-----: | | :--: | :-: | :-----: |

View File

@ -9,7 +9,11 @@ import java.io.UnsupportedEncodingException;
public class Console { public class Console {
private static final String FILE_PREFIX = "tmp/"; private static final String FILE_PREFIX = "tmp/";
public static boolean filePrefixEnabled = false; private static boolean filePrefixEnabled;
public static void enableFilePrefix() {
Console.filePrefixEnabled = true;
}
public static String newline() { public static String newline() {
return System.lineSeparator(); return System.lineSeparator();

View File

@ -12,22 +12,22 @@ public final class Variables {
private static final Object lock = new Object(); private static final Object lock = new Object();
private static class Scope { private static class Scope {
public final Scope parent; final Scope parent;
public final Map<String, Value> variables; final Map<String, Value> variables;
public Scope() { Scope() {
this(null); this(null);
} }
public Scope(Scope parent) { Scope(Scope parent) {
this.parent = parent; this.parent = parent;
variables = new ConcurrentHashMap<>(); variables = new ConcurrentHashMap<>();
} }
} }
private static class ScopeFindData { private static class ScopeFindData {
public boolean isFound; boolean isFound;
public Scope scope; Scope scope;
} }
private static volatile Scope scope; private static volatile Scope scope;
@ -46,14 +46,13 @@ public final class Variables {
scope.variables.put("false", NumberValue.ZERO); scope.variables.put("false", NumberValue.ZERO);
} }
public static void push() { static void push() {
synchronized (lock) { synchronized (lock) {
final Scope newScope = new Scope(scope); scope = new Scope(scope);
scope = newScope;
} }
} }
public static void pop() { static void pop() {
synchronized (lock) { synchronized (lock) {
if (scope.parent != null) { if (scope.parent != null) {
scope = scope.parent; scope = scope.parent;

View File

@ -319,9 +319,14 @@ public final class java implements Module {
final Class<?> clazz = types[i]; final Class<?> clazz = types[i];
if (arg == NULL) continue; if (arg == NULL) continue;
if (unboxed(clazz).isAssignableFrom(unboxed(valueToObject(arg).getClass()))) {
continue; final Class<?> unboxed = unboxed(clazz);
} boolean assignable = unboxed != null;
final Object object = valueToObject(arg);
assignable = assignable && (object != null);
assignable = assignable && (unboxed.isAssignableFrom(object.getClass()));
if (assignable) continue;
return false; return false;
} }
return true; return true;

View File

@ -1,5 +1,6 @@
package com.annimon.ownlang.modules.robot; package com.annimon.ownlang.modules.robot;
import com.annimon.ownlang.Console;
import com.annimon.ownlang.lib.Arguments; import com.annimon.ownlang.lib.Arguments;
import com.annimon.ownlang.lib.ArrayValue; import com.annimon.ownlang.lib.ArrayValue;
import com.annimon.ownlang.lib.Function; import com.annimon.ownlang.lib.Function;
@ -43,7 +44,6 @@ public final class robot_exec implements Function {
return NumberValue.ZERO; return NumberValue.ZERO;
} }
} catch (Exception ex) { } catch (Exception ex) {
ex.printStackTrace();
return NumberValue.ZERO; return NumberValue.ZERO;
} }
} }

View File

@ -29,6 +29,7 @@ public final class std_sync implements Function {
try { try {
return queue.take(); return queue.take();
} catch (InterruptedException ex) { } catch (InterruptedException ex) {
Thread.currentThread().interrupt();
throw new RuntimeException(ex); throw new RuntimeException(ex);
} }
} }

View File

@ -30,7 +30,7 @@ public final class Parser {
private static final EnumMap<TokenType, BinaryExpression.Operator> ASSIGN_OPERATORS; private static final EnumMap<TokenType, BinaryExpression.Operator> ASSIGN_OPERATORS;
static { static {
ASSIGN_OPERATORS = new EnumMap(TokenType.class); ASSIGN_OPERATORS = new EnumMap<>(TokenType.class);
ASSIGN_OPERATORS.put(TokenType.EQ, null); ASSIGN_OPERATORS.put(TokenType.EQ, null);
ASSIGN_OPERATORS.put(TokenType.PLUSEQ, BinaryExpression.Operator.ADD); ASSIGN_OPERATORS.put(TokenType.PLUSEQ, BinaryExpression.Operator.ADD);
ASSIGN_OPERATORS.put(TokenType.MINUSEQ, BinaryExpression.Operator.SUBTRACT); ASSIGN_OPERATORS.put(TokenType.MINUSEQ, BinaryExpression.Operator.SUBTRACT);
@ -305,7 +305,7 @@ public final class Parser {
} }
if (lookMatch(0, TokenType.DOT)) { if (lookMatch(0, TokenType.DOT)) {
final List<Expression> indices = variableSuffix(); final List<Expression> indices = variableSuffix();
if (indices == null | indices.isEmpty()) return expr; if (indices == null || indices.isEmpty()) return expr;
if (lookMatch(0, TokenType.LPAREN)) { if (lookMatch(0, TokenType.LPAREN)) {
// next function call // next function call

View File

@ -221,7 +221,7 @@ public final class MatchExpression extends InterruptableNode implements Expressi
} }
public static class ConstantPattern extends Pattern { public static class ConstantPattern extends Pattern {
public Value constant; Value constant;
public ConstantPattern(Value pattern) { public ConstantPattern(Value pattern) {
this.constant = pattern; this.constant = pattern;
@ -247,13 +247,13 @@ public final class MatchExpression extends InterruptableNode implements Expressi
} }
public static class ListPattern extends Pattern { public static class ListPattern extends Pattern {
public List<String> parts; List<String> parts;
public ListPattern() { public ListPattern() {
this(new ArrayList<>()); this(new ArrayList<>());
} }
public ListPattern(List<String> parts) { ListPattern(List<String> parts) {
this.parts = parts; this.parts = parts;
} }

View File

@ -4,7 +4,7 @@ import com.annimon.ownlang.lib.Value;
public final class VariableInfo { public final class VariableInfo {
public Value value; public Value value;
public int modifications; int modifications;
@Override @Override
public String toString() { public String toString() {

View File

@ -18,7 +18,7 @@ import java.util.List;
public final class Sandbox { public final class Sandbox {
public static void main(String[] args) throws IOException { public static void main(String[] args) throws IOException {
Console.filePrefixEnabled = true; Console.enableFilePrefix();
final String input = SourceLoader.readAndCloseStream(System.in); final String input = SourceLoader.readAndCloseStream(System.in);
dumpInputArguments(input, args); dumpInputArguments(input, args);