Uses 2164K of libraries. Click here for Pure Java version (68562L/364K).
1 | concept G22LeftArrowScript > G22Text { |
2 | // the latest code that has been cleared to auto-run (if any) |
3 | settableWithVar ClearForAutoRun<S> clearedForAutoRun; |
4 | |
5 | // auto-run when project is opened |
6 | settableWithVar bool runOnProjectOpen; |
7 | |
8 | // only when runOnProjectOpen is seT: |
9 | // when to run in sequence (sorted with alphanumIC) |
10 | settableWithVar S runOrder; |
11 | |
12 | // run stats |
13 | long runCount; |
14 | |
15 | // info about last result (or error) of script run by mode |
16 | Map<G22ScriptMode, WithTimestamp<PersistableOKOrError<G22TypeDesc>>> lastResultByMode; |
17 | |
18 | // is there a newer version of this script? |
19 | new Ref<G22LeftArrowScript> supercededBy; |
20 | |
21 | // Put meta-functions here (e.g. for improving an IDE showing |
22 | // this script) |
23 | settableWithVar S metaCode; |
24 | |
25 | void _doneLoading2 :: after { |
26 | //print("_doneLoading " + this); |
27 | cMigrateField(this, "code", "text"); |
28 | } |
29 | |
30 | toString { |
31 | if (empty(description)) |
32 | ret myType() + " " + id; |
33 | else |
34 | ret "Script " + id + ": " + description; |
35 | } |
36 | |
37 | bool isSavedDistinctFromAutoRunVersion() { ret isSaved() && !eq(text, codeForAutoRun()); } |
38 | bool isClearForAutoRun() { ret clearedForAutoRun != null; } |
39 | |
40 | S codeForAutoRun() { ret getVar(clearedForAutoRun()); } |
41 | |
42 | // return code clear for auto run if available |
43 | // otherwise returns saved code if available |
44 | // in all other cases returns null |
45 | // (never returns text being edited) |
46 | S safestCode() { ret or(codeForAutoRun(), stableText()); } |
47 | |
48 | void clearForAutoRun { |
49 | if (!isSaved()) ret; |
50 | S text = text(); |
51 | saveFieldToHistory("Auto-runnable code", text); |
52 | clearedForAutoRun(new ClearForAutoRun(text)); |
53 | } |
54 | |
55 | void forgetAutoRunCode { |
56 | if (!isClearForAutoRun()) ret; |
57 | saveFieldToHistory("Auto-runnable code", null); |
58 | clearedForAutoRun(null); |
59 | compileResultForAutoRun = null; |
60 | } |
61 | |
62 | void forgetCompileResults { |
63 | compileResultForAutoRun = compileResultForSaved = null; |
64 | } |
65 | |
66 | GazelleV_LeftArrowScriptParser makeParser() { |
67 | ret g22utils().leftArrowParser() |
68 | .sourceInfo(this); |
69 | } |
70 | |
71 | LASCompileResult newCompileResult() { ret new LASCompileResult; } |
72 | |
73 | LASCompileResult returnOrCompile(LASCompileResult lastCompileResult, S code) { |
74 | if (g22utils().compileResultValid(lastCompileResult, code)) |
75 | ret lastCompileResult; |
76 | var cr = newCompileResult(); |
77 | cr.script(code); |
78 | var parser = makeParser(); |
79 | cr.parser(parser); |
80 | cr.compile(); |
81 | ret cr; |
82 | } |
83 | |
84 | transient LASCompileResult compileResultForAutoRun; |
85 | LASCompileResult compileForAutoRun() { |
86 | S code = codeForAutoRun(); |
87 | if (code == null) null; |
88 | var cr = returnOrCompile(compileResultForAutoRun, code); |
89 | ret compileResultForAutoRun = cr; |
90 | } |
91 | |
92 | transient LASCompileResult compileResultForSaved; |
93 | LASCompileResult compileSaved() { |
94 | S code = stableText(); |
95 | if (code == null) null; |
96 | var cr = returnOrCompile(compileResultForSaved, code); |
97 | ret compileResultForSaved = cr; |
98 | } |
99 | |
100 | transient LASCompileResult compileResultForEditing; |
101 | LASCompileResult compileEditing() { |
102 | S code = editingText(); |
103 | if (code == null) null; |
104 | var cr = returnOrCompile(compileResultForEditing, code); |
105 | ret compileResultForEditing = cr; |
106 | } |
107 | |
108 | LASCompileResult safestCompileResult() { |
109 | try object compileForAutoRun(); |
110 | ret compileSaved(); |
111 | } |
112 | |
113 | LASCompileResult latestCompileResult() { |
114 | try object compileEditing(); |
115 | try object compileSaved(); |
116 | ret compileForAutoRun(); |
117 | } |
118 | |
119 | LASCompileResult latestRunnableCompileResult() { |
120 | var cr = compileEditing(); |
121 | if (cr != null && cr.runnable()) ret cr; |
122 | cr = compileSaved(); |
123 | if (cr != null && cr.runnable()) ret cr; |
124 | cr = compileForAutoRun(); |
125 | if (cr != null && cr.runnable()) ret cr; |
126 | null; |
127 | } |
128 | |
129 | O evaluateWithoutTimeout() { |
130 | var cr = safestCompileResult(); |
131 | if (cr == null) |
132 | fail("Not saved: " + this); |
133 | |
134 | temp g22utils().enter(); // enter module |
135 | ret cr.parsedScriptMandatory()!; |
136 | } |
137 | |
138 | O evaluateAutoRunWithoutTimeout() { |
139 | var cr = compileForAutoRun(); |
140 | if (cr == null) |
141 | fail("Not cleared for auto-run: " + this); |
142 | |
143 | temp g22utils().enter(); // enter module |
144 | ret cr.parsedScriptMandatory()!; |
145 | } |
146 | |
147 | S renderRunOnProjectOpenStatus() { |
148 | ret runOnProjectOpen |
149 | ? "Yes" + appendBracketed(appendPrefixIfNempty("prio ", runOrder)) |
150 | : null; |
151 | } |
152 | |
153 | Set<S> allTexts() { |
154 | ret addAndReturnCollection(super.allTexts(), codeForAutoRun()); |
155 | } |
156 | } |
Began life as a copy of #1034204
download show line numbers debug dex old transpilations
Travelled to 4 computer(s): bhatertpkbcr, ekrmjmnbrukm, mowyntqkapby, mqqgnosmbjvj
No comments. add comment
Snippet ID: | #1034255 |
Snippet name: | G22LeftArrowScript (script as a concept) |
Eternal ID of this version: | #1034255/89 |
Text MD5: | bb639f3077124d5d7cc47878831b732b |
Transpilation MD5: | 5e3091ea6095d63095648ca5cc6a7537 |
Author: | stefan |
Category: | javax |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2023-04-27 18:30:59 |
Source code size: | 4601 bytes / 156 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 457 / 1160 |
Version history: | 88 change(s) |
Referenced in: | [show references] |