Skip to content

Commit

Permalink
Type detection more forgiving
Browse files Browse the repository at this point in the history
  • Loading branch information
EgonOlsen committed Dec 27, 2019
1 parent b79841c commit b7d8d6f
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 9 deletions.
Binary file modified dist/basicv2.jar
Binary file not shown.
29 changes: 21 additions & 8 deletions src/main/java/com/sixtyfour/elements/Variable.java
Original file line number Diff line number Diff line change
Expand Up @@ -91,16 +91,19 @@ public Variable(String name, Object value) {
String woa = name.replace("[]", "");
char c = woa.charAt(woa.length() - 1);
type = null;
if (c == '$') {
type = Type.STRING;
} else if (c == '%') {
type = Type.INTEGER;
} else if (Character.isLetter(c) || Character.isDigit(c)) {
type = Type.REAL;
}
findType(c);

if (type == null) {
throw new RuntimeException("Unknown variable type for: " + name);
int pos = woa.indexOf("{");
if (pos != -1) {
// This is trying to detect the type of something like L${T4}, which actually shouldn't occur
// in the first place, but for some reason still does.
c = woa.substring(pos - 1, pos).charAt(0);
findType(c);
}
if (type == null) {
throw new RuntimeException("Unknown variable type for: " + name + "/" + woa);
}
}

if (value == null) {
Expand Down Expand Up @@ -137,6 +140,16 @@ public Variable(String name, Object value) {
this.setValue(value);
}

private void findType(char c) {
if (c == '$') {
type = Type.STRING;
} else if (c == '%') {
type = Type.INTEGER;
} else if (Character.isLetter(c) || Character.isDigit(c)) {
type = Type.REAL;
}
}

@Override
public List<CodeContainer> evalToCode(CompilerConfig config, Machine machine) {
List<String> ret = new ArrayList<String>();
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/com/sixtyfour/elements/commands/Sys.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ public String parse(CompilerConfig config, String linePart, int lineCnt, int lin

@Override
public List<CodeContainer> evalToCode(CompilerConfig config, Machine machine) {
if (pars.size() > 1) {
throw new RuntimeException("Too many parameters in SYS call: " + term.getInitial());
}
if (addr.isConstant()) {
// Shortcut for SYS XXXX, which should be the majority of calls
int memAddr = VarUtils.getInt(addr.eval(machine));
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/sixtyfour/parser/Parser.java
Original file line number Diff line number Diff line change
Expand Up @@ -892,7 +892,7 @@ private static Atom createAtom(CompilerConfig config, String part, Map<String, T
Atom str = new Constant<String>(ct);
return str;
} else {
throw new RuntimeException("String not terminated: " + part);
throw new RuntimeException("String not properly terminated: " + part);
}
}
if (part.endsWith("\"")) {
Expand Down

0 comments on commit b7d8d6f

Please sign in to comment.