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

87
LINES

< > BotCompany Repo | #1034041 // GazelleV_LeftArrowScript (rewrite rejected by Java compiler)

JavaX fragment (include)

1  
/* e.g.
2  
3  
  overlay <- ScreenOverlay
4  
  bounds <- rightScreenBounds
5  
  overlay bounds bounds
6  
  overlay show
7  
*/
8  
  
9  
// We're using SynchronizedList as a list wrapper
10  
sclass GazelleV_LeftArrowScript extends SynchronizedList<GazelleV_LeftArrowScript.Evaluable> is GazelleV_LeftArrowScript.Evaluable {
11  
  interface Evaluable {
12  
    public O get(VarContext ctx default new);
13  
  }
14  
  
15  
  *() { super(new L); }
16  
  
17  
  public O get(VarContext ctx) {
18  
    O result = null;
19  
    for (step : this)
20  
      result = step.get(ctx);
21  
    ret result;
22  
  }
23  
  
24  
  toString { ret pnlToLines(this); }
25  
26  
  srecord noeq FunctionDef(S name, LS args, Evaluable body) {}
27  
  
28  
  srecord noeq Assignment(S var, Evaluable expression) is Evaluable {
29  
    public O get(VarContext ctx) {
30  
      O o = expression.get(ctx);
31  
      ctx.set(var, o);
32  
      ret o;
33  
    }
34  
    
35  
    toString { ret var + " <- " + expression; }
36  
  }
37  
  
38  
  persistable sclass NewObject is Evaluable {
39  
    Class c;
40  
    L<Evaluable> args;
41  
    
42  
    *(Class *c) {}
43  
    *(Class *c, L<Evaluable> *args) {}
44  
    
45  
    public O get(VarContext ctx) {
46  
      ret callConstructor(c, mapToArray(args, arg -> arg.get(ctx)));
47  
    }
48  
    
49  
    toString { ret "new " + formatFunctionCall(className(c), args); }
50  
  }
51  
  
52  
  srecord noeq CallFunction(FunctionDef f, L<Evaluable> args) is Evaluable {
53  
    public O get(VarContext ctx) {
54  
      var ctx2 = new VarContext(ctx);
55  
      for (S declared, Evaluable actual : unpair zipLists(f.args, args))
56  
        ctx2.put(declared, actual.get(ctx));
57  
      print ifdef GazelleV_LeftArrowScript_debug(ctx2 := ctx2.vars);
58  
      ret f.body.get(ctx2);
59  
    }
60  
    
61  
    toString { ret formatFunctionCall(f.name, args); }
62  
  }
63  
  
64  
  srecord noeq GetVar(S var) is Evaluable {
65  
    public O get(VarContext ctx) {
66  
      ret ctx.get(var);
67  
    }
68  
    
69  
    toString { ret var; }
70  
  }
71  
  
72  
  srecord noeq Const(O value) is Evaluable {
73  
    public O get(VarContext ctx) {
74  
      ret value;
75  
    }
76  
    
77  
    toString { ret strOrClassName(value); }
78  
  }
79  
  
80  
  srecord CallMethod(Evaluable target, S methodName, L<Evaluable> args) is Evaluable {
81  
    public O get(VarContext ctx) {
82  
      ret call(target.get(ctx), methodName, mapToArray(args, arg -> arg.get(ctx)));
83  
    }
84  
    
85  
    toString { ret target + "." + formatFunctionCall(methodName, args); }
86  
  }
87  
}

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: #1034041
Snippet name: GazelleV_LeftArrowScript (rewrite rejected by Java compiler)
Eternal ID of this version: #1034041/1
Text MD5: cff0d0996751ef1e2dd04f2e867599d3
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:17:40
Source code size: 2339 bytes / 87 lines
Pitched / IR pitched: No / No
Views / Downloads: 119 / 148
Referenced in: [show references]