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

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
[![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 |
| :--: | :-: | :-----: |

View File

@ -9,7 +9,11 @@ import java.io.UnsupportedEncodingException;
public class Console {
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() {
return System.lineSeparator();

View File

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

View File

@ -319,9 +319,14 @@ public final class java implements Module {
final Class<?> clazz = types[i];
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 true;

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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