Skip to content

Commit

Permalink
Sys
Browse files Browse the repository at this point in the history
  • Loading branch information
dzaima committed Jun 27, 2021
1 parent 1c04096 commit 927684d
Showing 13 changed files with 263 additions and 179 deletions.
19 changes: 9 additions & 10 deletions src/APL/Exec.java
Original file line number Diff line number Diff line change
@@ -33,8 +33,7 @@ public Exec(LineTok ln, Scope sc) {

private void printlvl(Object... args) {
if (!Main.debug) return;
for (int i = 0; i < Main.printlvl; i++) Main.print(" ");
Main.printdbg(args);
Main.printdbg(sc, Main.repeat(" ", Main.printlvl), args);
}
private Stack<Token> left;
public Obj exec() {
@@ -150,7 +149,7 @@ public Obj exec() {
}

// oh well that failed
throw new SyntaxError("couldn't join everything up into a single expression", pollL());
throw new SyntaxError("Failed to parse expression", pollL());
}
return pollS();
}
@@ -670,7 +669,7 @@ private Obj valueOfRaw(Token t) {

case '⍬': return new DoubleArr(DoubleArr.EMPTY);
case '⎕': return new Quad(sc);
case '⍞': return new QuoteQuad();
case '⍞': return new QuoteQuad(sc);
case '⍺': Obj o = sc.get("⍺"); if(o == null) throw new SyntaxError("No ⍺ found", t); return o;
case '⍵': o = sc.get("⍵"); if(o == null) throw new SyntaxError("No ⍵ found", t); return o;
case '∇': o = sc.get("∇"); if(o == null) throw new SyntaxError("No ∇ found", t); return o;
@@ -684,15 +683,15 @@ private Obj valueOfRaw(Token t) {
if (t instanceof StrTok) return ((StrTok) t).val;
if (t instanceof SetTok) return SetBuiltin.inst;
if (t instanceof NameTok) return sc.getVar(((NameTok) t).name);
if (t instanceof LineTok) return Main.exec((LineTok) t, sc);
if (t instanceof LineTok) return Main.rexec((LineTok) t, sc);
if (t instanceof ParenTok) {
List<LineTok> ts = ((ParenTok) t).tokens;
int size = ts.size();
if (size == 0) return new StrMap();
LineTok fst = ts.get(0);
if (size==1 && fst.colonPos()==-1) {
if (((ParenTok) t).hasDmd) return new Shape1Arr(Main.vexec(ts.get(0), sc));
return Main.exec(ts.get(0), sc);
return Main.rexec(ts.get(0), sc);
}
if (fst.tokens != null && fst.colonPos() != -1) { // map constants
Scope nsc = new Scope(sc);
@@ -708,24 +707,24 @@ private Obj valueOfRaw(Token t) {
else throw new SyntaxError("expected a key name, got " + name.toRepr(), name);
List<Token> tokens = ct.tokens.subList(2, ct.tokens.size());

Obj val = Main.oexec(LineTok.inherit(tokens), nsc);
Obj val = Main.exec(LineTok.inherit(tokens), nsc);
res.setStr(key, val);
}
return res;
} else { // array
Obj fo = Main.oexec(fst, sc);
Obj fo = Main.exec(fst, sc);
if (fo instanceof Value) { // value array
Value[] vs = new Value[size];
for (int i = 0; i < ts.size(); i++) {
Obj o = i==0? fo : Main.oexec(ts.get(i), sc);
Obj o = i==0? fo : Main.exec(ts.get(i), sc);
if (!(o instanceof Value)) throw new DomainError("⋄-array contained " + o.humanType(true), o);
vs[i] = (Value) o;
}
return Arr.create(vs);
} else if (fo instanceof Fun) { // function array
Obj[] os = new Obj[size];
for (int i = 0; i < ts.size(); i++) {
Obj o = i==0? fo : Main.oexec(ts.get(i), sc);
Obj o = i==0? fo : Main.exec(ts.get(i), sc);
if (!(o instanceof Fun)) throw new DomainError("function array contained " + o.humanType(true), o);
os[i] = o;
}
Loading

0 comments on commit 927684d

Please sign in to comment.