Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

90
LINES

< > BotCompany Repo | #1034040 // GazelleV_LeftArrowScript backup

JavaX fragment (include)

/* e.g.

  overlay <- ScreenOverlay
  bounds <- rightScreenBounds
  overlay bounds bounds
  overlay show
*/
  
sclass GazelleV_LeftArrowScript > SimpleLeftToRightParser {
  interface Evaluable {
    public O get(VarContext ctx default new);
  }
  
  // We're using SynchronizedList as a list wrapper
  //sclass Script extends ArrayList<Evaluable> {
  sclass Script extends SynchronizedList<Evaluable> is Evaluable {
    *() { super(new L); }
    
    public O get(VarContext ctx) {
      O result = null;
      for (step : this)
        result = step.get(ctx);
      ret result;
    }
    
    toString { ret pnlToLines(this); }
  }
  
  srecord noeq FunctionDef(S name, LS args, Evaluable body) {}
  
  srecord noeq Assignment(S var, Evaluable expression) is Evaluable {
    public O get(VarContext ctx) {
      O o = expression.get(ctx);
      ctx.set(var, o);
      ret o;
    }
    
    toString { ret var + " <- " + expression; }
  }
  
  persistable sclass NewObject is Evaluable {
    Class c;
    L<Evaluable> args;
    
    *(Class *c) {}
    *(Class *c, L<Evaluable> *args) {}
    
    public O get(VarContext ctx) {
      ret callConstructor(c, mapToArray(args, arg -> arg.get(ctx)));
    }
    
    toString { ret "new " + formatFunctionCall(className(c), args); }
  }
  
  srecord noeq CallFunction(FunctionDef f, L<Evaluable> args) is Evaluable {
    public O get(VarContext ctx) {
      var ctx2 = new VarContext(ctx);
      for (S declared, Evaluable actual : unpair zipLists(f.args, args))
        ctx2.put(declared, actual.get(ctx));
      print ifdef GazelleV_LeftArrowScript_debug(ctx2 := ctx2.vars);
      ret f.body.get(ctx2);
    }
    
    toString { ret formatFunctionCall(f.name, args); }
  }
  
  srecord noeq GetVar(S var) is Evaluable {
    public O get(VarContext ctx) {
      ret ctx.get(var);
    }
    
    toString { ret var; }
  }
  
  srecord noeq Const(O value) is Evaluable {
    public O get(VarContext ctx) {
      ret value;
    }
    
    toString { ret strOrClassName(value); }
  }
  
  srecord CallMethod(Evaluable target, S methodName, L<Evaluable> args) is Evaluable {
    public O get(VarContext ctx) {
      ret call(target.get(ctx), methodName, mapToArray(args, arg -> arg.get(ctx)));
    }
    
    toString { ret target + "." + formatFunctionCall(methodName, args); }
  }
}

Author comment

Began life as a copy of #1033981

download  show line numbers  debug dex  old transpilations   

Travelled to 3 computer(s): bhatertpkbcr, mowyntqkapby, mqqgnosmbjvj

No comments. add comment

Snippet ID: #1034040
Snippet name: GazelleV_LeftArrowScript backup
Eternal ID of this version: #1034040/1
Text MD5: 80a424c40dc9c98971747a1bb65d8a73
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2022-01-18 02:14:20
Source code size: 2415 bytes / 90 lines
Pitched / IR pitched: No / No
Views / Downloads: 123 / 150
Referenced in: [show references]