Libraryless. Click here for Pure Java version (4384L/25K).
1 | sclass OpsOnVars { |
2 | MapSO vars = syncTreeMap(); |
3 | |
4 | sclass NotRunYet {} |
5 | static new NotRunYet notRunYet; |
6 | |
7 | *(O... _) { |
8 | addParamsToMap_inPlace(vars, _); |
9 | } |
10 | |
11 | O getVar aka get(S var) { ret vars.get(var); } |
12 | void setVar aka set(S var, O value) { if (var != null) vars.put(var, value); } |
13 | |
14 | record SetVar(S var, O value) is Runnable { |
15 | run { setVar(var, value); } |
16 | } |
17 | |
18 | // SINGLE-OPS (one input variable, one output variable) |
19 | |
20 | macro singleOpCtors { |
21 | *() {} |
22 | *(S *inVar, S *outVar) {} |
23 | } |
24 | |
25 | abstract noeq record SingleOp(S inVar, S outVar) is Runnable { |
26 | transient O value = notRunYet; |
27 | |
28 | abstract O perform(O arg); |
29 | |
30 | run { get(); } |
31 | |
32 | O get() { |
33 | value = perform(getVar(inVar)); |
34 | setVar(outVar, value); |
35 | ret value; |
36 | } |
37 | } |
38 | |
39 | // MULTI-OPS (multiple input variables, one output variable) |
40 | |
41 | abstract noeq record MultiOp(LS inVars, S outVar) is Runnable { |
42 | transient O value = notRunYet; |
43 | |
44 | abstract O perform(L values); |
45 | |
46 | *(S... vars) { |
47 | outVar = last(vars); |
48 | inVars = asListMinusLast(vars); |
49 | } |
50 | |
51 | run { get(); } |
52 | |
53 | O get() { |
54 | value = perform(map getVar(inVars); |
55 | setVar(outVar, value); |
56 | ret value; |
57 | } |
58 | } |
59 | |
60 | macro multiOpCtors { |
61 | *() {} |
62 | *(LS *inVars, S *outVar) {} |
63 | *(S... vars) { super(vars); } |
64 | } |
65 | } |
Began life as a copy of #1032649
download show line numbers debug dex old transpilations
Travelled to 3 computer(s): bhatertpkbcr, mowyntqkapby, mqqgnosmbjvj
No comments. add comment
Snippet ID: | #1032804 |
Snippet name: | OpsOnVars [dev.] |
Eternal ID of this version: | #1032804/2 |
Text MD5: | 2ca1247fa9b87ad013a9d6401d8eeb29 |
Transpilation MD5: | 3117c881b5f1a0b5cf1abbe4a6d5d544 |
Author: | stefan |
Category: | javax |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2021-10-06 08:13:49 |
Source code size: | 1414 bytes / 65 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 131 / 192 |
Version history: | 1 change(s) |
Referenced in: | [show references] |