Skip to content

Commit c991ccc

Browse files
committed
rt: Support the notion of function knowing their runtime state by updating it when there is a clause case
1 parent 658370b commit c991ccc

File tree

1 file changed

+14
-10
lines changed

1 file changed

+14
-10
lines changed

src/main/java/org/piccode/rt/PiccodeClosure.java

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@ public PiccodeValue call(PiccodeValue arg) {
5656
computeStableClause();
5757
if (!clauses.isEmpty() || hasPatternParam(params)) {
5858
createWhenExpression(frame);
59+
if (creator instanceof FunctionAst func) {
60+
func.rtObject = this;
61+
}
5962
}
6063
Map<String, PiccodeValue> newArgs = new HashMap<>(appliedArgs);
6164
if (params.get(positionalIndex) instanceof Arg _arg) {
@@ -336,27 +339,28 @@ private List<Ast> getStableArgs(List<Ast> params) {
336339
for (int i = 0; i < params.size(); i++) {
337340
var param = params.get(i);
338341
if (!(param instanceof Arg)) {
339-
var arg = new Arg("$_PLACEHOLDER_ID_" + i + "__$");
340-
arg.file = file;
341-
arg.line = line;
342-
arg.column = column;
343-
newList.addLast(arg);
342+
var arg = new Arg("$_PLACEHOLDER_ID_" + i + "__$");
343+
arg.file = file;
344+
arg.line = line;
345+
arg.column = column;
346+
newList.addLast(arg);
344347
} else {
345348
newList.add(param);
346349
}
347350
}
348351
return newList;
349352
}
353+
350354
private List<Ast> getStableIds(List<Ast> params) {
351355
var newList = new ArrayList<Ast>();
352356
for (int i = 0; i < params.size(); i++) {
353357
var param = params.get(i);
354358
if (!(param instanceof Arg)) {
355-
var arg = new IdentifierAst("$_PLACEHOLDER_ID_" + i + "__$");
356-
arg.file = file;
357-
arg.line = line;
358-
arg.column = column;
359-
newList.addLast(arg);
359+
var arg = new IdentifierAst("$_PLACEHOLDER_ID_" + i + "__$");
360+
arg.file = file;
361+
arg.line = line;
362+
arg.column = column;
363+
newList.addLast(arg);
360364
} else {
361365
newList.add(param);
362366
}

0 commit comments

Comments
 (0)