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)

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

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: 125 / 153
Referenced in: [show references]