dirac-lang 0.1.17 → 0.1.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{chunk-3FECP4IA.js → chunk-E2MR7FMI.js} +1 -1
- package/dist/{chunk-OB7IXRFP.js → chunk-VZEKPMWN.js} +12 -12
- package/dist/cli.js +3 -3
- package/dist/index.js +2 -2
- package/dist/{interpreter-Y465JGHU.js → interpreter-MCDR5L7R.js} +1 -1
- package/dist/test-runner.js +1 -1
- package/examples/scope-test-nested.di +60 -0
- package/examples/scope-test.di +55 -0
- package/package.json +1 -1
- package/src/tags/call.ts +2 -2
- package/test-eval.di +4 -0
- package/tests/subroutine-nested-calls.test.di +32 -0
- package/tests/subroutine-sequential-calls.test.di +36 -0
|
@@ -310,8 +310,8 @@ async function executeCallInternal(session, subroutine, callElement, isExtendExe
|
|
|
310
310
|
} finally {
|
|
311
311
|
session.skipSubroutineRegistration = oldSkipFlag;
|
|
312
312
|
popParameters(session);
|
|
313
|
-
session.varBoundary = oldBoundary;
|
|
314
313
|
cleanToBoundary(session);
|
|
314
|
+
session.varBoundary = oldBoundary;
|
|
315
315
|
session.isReturn = wasReturn;
|
|
316
316
|
}
|
|
317
317
|
}
|
|
@@ -396,12 +396,12 @@ async function executeIf(session, element) {
|
|
|
396
396
|
const condition = await evaluatePredicate(session, conditionElement);
|
|
397
397
|
if (condition) {
|
|
398
398
|
if (thenElement) {
|
|
399
|
-
const { integrateChildren: integrateChildren2 } = await import("./interpreter-
|
|
399
|
+
const { integrateChildren: integrateChildren2 } = await import("./interpreter-MCDR5L7R.js");
|
|
400
400
|
await integrateChildren2(session, thenElement);
|
|
401
401
|
}
|
|
402
402
|
} else {
|
|
403
403
|
if (elseElement) {
|
|
404
|
-
const { integrateChildren: integrateChildren2 } = await import("./interpreter-
|
|
404
|
+
const { integrateChildren: integrateChildren2 } = await import("./interpreter-MCDR5L7R.js");
|
|
405
405
|
await integrateChildren2(session, elseElement);
|
|
406
406
|
}
|
|
407
407
|
}
|
|
@@ -414,7 +414,7 @@ async function evaluatePredicate(session, predicateElement) {
|
|
|
414
414
|
return await evaluateCondition(session, predicateElement);
|
|
415
415
|
}
|
|
416
416
|
const outputLengthBefore = session.output.length;
|
|
417
|
-
const { integrate: integrate2 } = await import("./interpreter-
|
|
417
|
+
const { integrate: integrate2 } = await import("./interpreter-MCDR5L7R.js");
|
|
418
418
|
await integrate2(session, predicateElement);
|
|
419
419
|
const newOutputChunks = session.output.slice(outputLengthBefore);
|
|
420
420
|
const result = newOutputChunks.join("").trim();
|
|
@@ -437,11 +437,11 @@ async function evaluateCondition(session, condElement) {
|
|
|
437
437
|
}
|
|
438
438
|
const outputLengthBefore = session.output.length;
|
|
439
439
|
const args = [];
|
|
440
|
-
const { integrate: integrate2 } = await import("./interpreter-
|
|
440
|
+
const { integrate: integrate2 } = await import("./interpreter-MCDR5L7R.js");
|
|
441
441
|
for (const child of condElement.children) {
|
|
442
442
|
if (child.tag.toLowerCase() === "arg") {
|
|
443
443
|
const argOutputStart = session.output.length;
|
|
444
|
-
const { integrateChildren: integrateChildren2 } = await import("./interpreter-
|
|
444
|
+
const { integrateChildren: integrateChildren2 } = await import("./interpreter-MCDR5L7R.js");
|
|
445
445
|
await integrateChildren2(session, child);
|
|
446
446
|
const newChunks = session.output.slice(argOutputStart);
|
|
447
447
|
const argValue = newChunks.join("");
|
|
@@ -1244,7 +1244,7 @@ async function executeTagCheck(session, element) {
|
|
|
1244
1244
|
const executeTag = correctedTag || tagName;
|
|
1245
1245
|
console.error(`[tag-check] Executing <${executeTag}/> as all checks passed and execute=true.`);
|
|
1246
1246
|
const elementToExecute = correctedTag ? { ...child, tag: correctedTag } : child;
|
|
1247
|
-
const { integrate: integrate2 } = await import("./interpreter-
|
|
1247
|
+
const { integrate: integrate2 } = await import("./interpreter-MCDR5L7R.js");
|
|
1248
1248
|
await integrate2(session, elementToExecute);
|
|
1249
1249
|
}
|
|
1250
1250
|
}
|
|
@@ -1253,7 +1253,7 @@ async function executeTagCheck(session, element) {
|
|
|
1253
1253
|
// src/tags/throw.ts
|
|
1254
1254
|
async function executeThrow(session, element) {
|
|
1255
1255
|
const exceptionName = element.attributes?.name || "exception";
|
|
1256
|
-
const { integrateChildren: integrateChildren2 } = await import("./interpreter-
|
|
1256
|
+
const { integrateChildren: integrateChildren2 } = await import("./interpreter-MCDR5L7R.js");
|
|
1257
1257
|
const exceptionDom = {
|
|
1258
1258
|
tag: "exception-content",
|
|
1259
1259
|
attributes: { name: exceptionName },
|
|
@@ -1266,7 +1266,7 @@ async function executeThrow(session, element) {
|
|
|
1266
1266
|
// src/tags/try.ts
|
|
1267
1267
|
async function executeTry(session, element) {
|
|
1268
1268
|
setExceptionBoundary(session);
|
|
1269
|
-
const { integrateChildren: integrateChildren2 } = await import("./interpreter-
|
|
1269
|
+
const { integrateChildren: integrateChildren2 } = await import("./interpreter-MCDR5L7R.js");
|
|
1270
1270
|
await integrateChildren2(session, element);
|
|
1271
1271
|
unsetExceptionBoundary(session);
|
|
1272
1272
|
}
|
|
@@ -1276,7 +1276,7 @@ async function executeCatch(session, element) {
|
|
|
1276
1276
|
const exceptionName = element.attributes?.name || "exception";
|
|
1277
1277
|
const caughtCount = lookupException(session, exceptionName);
|
|
1278
1278
|
if (caughtCount > 0) {
|
|
1279
|
-
const { integrateChildren: integrateChildren2 } = await import("./interpreter-
|
|
1279
|
+
const { integrateChildren: integrateChildren2 } = await import("./interpreter-MCDR5L7R.js");
|
|
1280
1280
|
await integrateChildren2(session, element);
|
|
1281
1281
|
}
|
|
1282
1282
|
flushCurrentException(session);
|
|
@@ -1285,7 +1285,7 @@ async function executeCatch(session, element) {
|
|
|
1285
1285
|
// src/tags/exception.ts
|
|
1286
1286
|
async function executeException(session, element) {
|
|
1287
1287
|
const exceptions = getCurrentExceptions(session);
|
|
1288
|
-
const { integrateChildren: integrateChildren2 } = await import("./interpreter-
|
|
1288
|
+
const { integrateChildren: integrateChildren2 } = await import("./interpreter-MCDR5L7R.js");
|
|
1289
1289
|
for (const exceptionDom of exceptions) {
|
|
1290
1290
|
await integrateChildren2(session, exceptionDom);
|
|
1291
1291
|
}
|
|
@@ -1425,7 +1425,7 @@ async function executeForeach(session, element) {
|
|
|
1425
1425
|
const parser2 = new DiracParser2();
|
|
1426
1426
|
try {
|
|
1427
1427
|
const fromElement = parser2.parse(fromAttr);
|
|
1428
|
-
const { integrate: integrate2 } = await import("./interpreter-
|
|
1428
|
+
const { integrate: integrate2 } = await import("./interpreter-MCDR5L7R.js");
|
|
1429
1429
|
await integrate2(session, fromElement);
|
|
1430
1430
|
} catch (e) {
|
|
1431
1431
|
session.output = savedOutput;
|
package/dist/cli.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import {
|
|
3
3
|
execute
|
|
4
|
-
} from "./chunk-
|
|
5
|
-
import "./chunk-
|
|
4
|
+
} from "./chunk-E2MR7FMI.js";
|
|
5
|
+
import "./chunk-VZEKPMWN.js";
|
|
6
6
|
import "./chunk-HRHAMPOB.js";
|
|
7
7
|
import "./chunk-E7PWEMZA.js";
|
|
8
8
|
import "./chunk-52ED23DR.js";
|
|
@@ -13,7 +13,7 @@ import "dotenv/config";
|
|
|
13
13
|
// package.json
|
|
14
14
|
var package_default = {
|
|
15
15
|
name: "dirac-lang",
|
|
16
|
-
version: "0.1.
|
|
16
|
+
version: "0.1.18",
|
|
17
17
|
description: "LLM-Augmented Declarative Execution",
|
|
18
18
|
type: "module",
|
|
19
19
|
main: "dist/index.js",
|
package/dist/index.js
CHANGED
|
@@ -2,10 +2,10 @@ import {
|
|
|
2
2
|
createLLMAdapter,
|
|
3
3
|
execute,
|
|
4
4
|
executeUserCommand
|
|
5
|
-
} from "./chunk-
|
|
5
|
+
} from "./chunk-E2MR7FMI.js";
|
|
6
6
|
import {
|
|
7
7
|
integrate
|
|
8
|
-
} from "./chunk-
|
|
8
|
+
} from "./chunk-VZEKPMWN.js";
|
|
9
9
|
import {
|
|
10
10
|
DiracParser
|
|
11
11
|
} from "./chunk-HRHAMPOB.js";
|
package/dist/test-runner.js
CHANGED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
<!-- Test nested subroutine calls with variable scope -->
|
|
2
|
+
<dirac>
|
|
3
|
+
<output>
|
|
4
|
+
============ Test: Nested Subroutine Calls with Variable Scope ============
|
|
5
|
+
</output>
|
|
6
|
+
|
|
7
|
+
<!-- Define main scope variables -->
|
|
8
|
+
<eval name="a">return "value-a"</eval>
|
|
9
|
+
<eval name="b">return "value-b"</eval>
|
|
10
|
+
<eval name="c">return "value-c"</eval>
|
|
11
|
+
|
|
12
|
+
<output>
|
|
13
|
+
Main scope: a=<variable name="a" />, b=<variable name="b" />, c=<variable name="c" />
|
|
14
|
+
</output>
|
|
15
|
+
|
|
16
|
+
<!-- Subroutine that calls another subroutine -->
|
|
17
|
+
<subroutine name="outer-sub" param-x="type:string:" param-y="type:string:">
|
|
18
|
+
<output> Outer subroutine - x: <variable name="x" />, y: <variable name="y" /></output>
|
|
19
|
+
|
|
20
|
+
<!-- Define local variable in outer sub -->
|
|
21
|
+
<eval name="outer_local">return "outer-value"</eval>
|
|
22
|
+
<output> Outer local: <variable name="outer_local" /></output>
|
|
23
|
+
|
|
24
|
+
<!-- Call inner subroutine -->
|
|
25
|
+
<call name="inner-sub" p="$x" q="$y"/>
|
|
26
|
+
|
|
27
|
+
<!-- Check outer variables still exist after inner call -->
|
|
28
|
+
<output> After inner call - x: <variable name="x" />, y: <variable name="y" />, outer_local: <variable name="outer_local" /></output>
|
|
29
|
+
</subroutine>
|
|
30
|
+
|
|
31
|
+
<!-- Inner subroutine -->
|
|
32
|
+
<subroutine name="inner-sub" param-p="type:string:" param-q="type:string:">
|
|
33
|
+
<output> Inner subroutine - p: <variable name="p" />, q: <variable name="q" /></output>
|
|
34
|
+
<eval name="inner_local">return "inner-value"</eval>
|
|
35
|
+
<output> Inner local: <variable name="inner_local" /></output>
|
|
36
|
+
</subroutine>
|
|
37
|
+
|
|
38
|
+
<output>
|
|
39
|
+
Calling outer-sub with a and b...
|
|
40
|
+
</output>
|
|
41
|
+
<call name="outer-sub" x="$a" y="$b"/>
|
|
42
|
+
|
|
43
|
+
<output>
|
|
44
|
+
After outer-sub, checking main scope:
|
|
45
|
+
a=<variable name="a" />, b=<variable name="b" />, c=<variable name="c" />
|
|
46
|
+
</output>
|
|
47
|
+
|
|
48
|
+
<!-- Call outer-sub again to ensure no cumulative scope pollution -->
|
|
49
|
+
<output>
|
|
50
|
+
Calling outer-sub AGAIN with b and c...
|
|
51
|
+
</output>
|
|
52
|
+
<call name="outer-sub" x="$b" y="$c"/>
|
|
53
|
+
|
|
54
|
+
<output>
|
|
55
|
+
After second outer-sub call:
|
|
56
|
+
a=<variable name="a" />, b=<variable name="b" />, c=<variable name="c" />
|
|
57
|
+
|
|
58
|
+
============ Test Complete ============
|
|
59
|
+
</output>
|
|
60
|
+
</dirac>
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
<dirac>
|
|
2
|
+
<!-- Test library with two simple subroutines -->
|
|
3
|
+
<subroutine name="first-sub"
|
|
4
|
+
param-x="string"
|
|
5
|
+
param-y="string">
|
|
6
|
+
<output>First subroutine - x: <variable name="x" />, y: <variable name="y" /></output>
|
|
7
|
+
</subroutine>
|
|
8
|
+
|
|
9
|
+
<subroutine name="second-sub"
|
|
10
|
+
param-x="string"
|
|
11
|
+
param-y="string"
|
|
12
|
+
param-z="string">
|
|
13
|
+
<output>Second subroutine - x: <variable name="x" />, y: <variable name="y" />, z: <variable name="z" /></output>
|
|
14
|
+
</subroutine>
|
|
15
|
+
|
|
16
|
+
<!-- Main execution -->
|
|
17
|
+
<output>============ Test: Sequential Subroutine Calls ============</output>
|
|
18
|
+
<output></output>
|
|
19
|
+
|
|
20
|
+
<!-- Define variables in main scope -->
|
|
21
|
+
<defvar name="x" trim="true">value-x</defvar>
|
|
22
|
+
<defvar name="y" trim="true">value-y</defvar>
|
|
23
|
+
<defvar name="z" trim="true">value-z</defvar>
|
|
24
|
+
|
|
25
|
+
<output>Variables defined in main scope:</output>
|
|
26
|
+
<output> x = <variable name="x" /></output>
|
|
27
|
+
<output> y = <variable name="y" /></output>
|
|
28
|
+
<output> z = <variable name="z" /></output>
|
|
29
|
+
<output></output>
|
|
30
|
+
|
|
31
|
+
<!-- Call first subroutine -->
|
|
32
|
+
<output>Calling first-sub with x="$x" y="$y"</output>
|
|
33
|
+
<first-sub x="$x" y="$y" />
|
|
34
|
+
<output></output>
|
|
35
|
+
|
|
36
|
+
<!-- Check if variables still exist after first call -->
|
|
37
|
+
<output>After first-sub, checking main scope variables:</output>
|
|
38
|
+
<output> x = <variable name="x" /></output>
|
|
39
|
+
<output> y = <variable name="y" /></output>
|
|
40
|
+
<output> z = <variable name="z" /></output>
|
|
41
|
+
<output></output>
|
|
42
|
+
|
|
43
|
+
<!-- Call second subroutine -->
|
|
44
|
+
<output>Calling second-sub with x="$x" y="$y" z="$z"</output>
|
|
45
|
+
<second-sub x="$x" y="$y" z="$z" />
|
|
46
|
+
<output></output>
|
|
47
|
+
|
|
48
|
+
<output>After second-sub, checking main scope variables:</output>
|
|
49
|
+
<output> x = <variable name="x" /></output>
|
|
50
|
+
<output> y = <variable name="y" /></output>
|
|
51
|
+
<output> z = <variable name="z" /></output>
|
|
52
|
+
<output></output>
|
|
53
|
+
|
|
54
|
+
<output>============ Test Complete ============</output>
|
|
55
|
+
</dirac>
|
package/package.json
CHANGED
package/src/tags/call.ts
CHANGED
|
@@ -200,9 +200,9 @@ async function executeCallInternal(
|
|
|
200
200
|
// Pop parameter stack
|
|
201
201
|
popParameters(session);
|
|
202
202
|
|
|
203
|
-
// Clean up scope (keep visible variables)
|
|
204
|
-
session.varBoundary = oldBoundary;
|
|
203
|
+
// Clean up scope (keep visible variables) BEFORE restoring boundary
|
|
205
204
|
cleanToBoundary(session);
|
|
205
|
+
session.varBoundary = oldBoundary;
|
|
206
206
|
session.isReturn = wasReturn;
|
|
207
207
|
}
|
|
208
208
|
}
|
package/test-eval.di
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
<!-- TEST: subroutine_nested_calls_preserve_scope -->
|
|
2
|
+
<!-- EXPECT: main: a=x b=y c=z
|
|
3
|
+
outer: p=x q=y
|
|
4
|
+
inner: r=x s=y
|
|
5
|
+
outer after inner: p=x q=y
|
|
6
|
+
main after outer: a=x b=y c=z -->
|
|
7
|
+
<dirac>
|
|
8
|
+
<!-- Inner subroutine -->
|
|
9
|
+
<subroutine name="inner" param-r="string" param-s="string">
|
|
10
|
+
<output>inner: r=<variable name="r" /> s=<variable name="s" /></output>
|
|
11
|
+
</subroutine>
|
|
12
|
+
|
|
13
|
+
<!-- Outer subroutine that calls inner -->
|
|
14
|
+
<subroutine name="outer" param-p="string" param-q="string">
|
|
15
|
+
<output>outer: p=<variable name="p" /> q=<variable name="q" /></output>
|
|
16
|
+
<inner r="$p" s="$q" />
|
|
17
|
+
<output>outer after inner: p=<variable name="p" /> q=<variable name="q" /></output>
|
|
18
|
+
</subroutine>
|
|
19
|
+
|
|
20
|
+
<!-- Define main scope variables -->
|
|
21
|
+
<defvar name="a" trim="true">x</defvar>
|
|
22
|
+
<defvar name="b" trim="true">y</defvar>
|
|
23
|
+
<defvar name="c" trim="true">z</defvar>
|
|
24
|
+
|
|
25
|
+
<output>main: a=<variable name="a" /> b=<variable name="b" /> c=<variable name="c" /></output>
|
|
26
|
+
|
|
27
|
+
<!-- Call outer which calls inner -->
|
|
28
|
+
<outer p="$a" q="$b" />
|
|
29
|
+
|
|
30
|
+
<!-- Verify main scope variables preserved -->
|
|
31
|
+
<output>main after outer: a=<variable name="a" /> b=<variable name="b" /> c=<variable name="c" /></output>
|
|
32
|
+
</dirac>
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
<!-- TEST: subroutine_sequential_calls_preserve_scope -->
|
|
2
|
+
<!-- EXPECT: x=a y=b z=c
|
|
3
|
+
first: x=a y=b
|
|
4
|
+
x=a y=b z=c
|
|
5
|
+
second: x=a y=b z=c
|
|
6
|
+
x=a y=b z=c -->
|
|
7
|
+
<dirac>
|
|
8
|
+
<!-- Define subroutines -->
|
|
9
|
+
<subroutine name="first-sub" param-x="string" param-y="string">
|
|
10
|
+
<output>first: x=<variable name="x" /> y=<variable name="y" /></output>
|
|
11
|
+
</subroutine>
|
|
12
|
+
|
|
13
|
+
<subroutine name="second-sub" param-x="string" param-y="string" param-z="string">
|
|
14
|
+
<output>second: x=<variable name="x" /> y=<variable name="y" /> z=<variable name="z" /></output>
|
|
15
|
+
</subroutine>
|
|
16
|
+
|
|
17
|
+
<!-- Define main scope variables -->
|
|
18
|
+
<defvar name="x" trim="true">a</defvar>
|
|
19
|
+
<defvar name="y" trim="true">b</defvar>
|
|
20
|
+
<defvar name="z" trim="true">c</defvar>
|
|
21
|
+
|
|
22
|
+
<!-- Verify initial state -->
|
|
23
|
+
<output>x=<variable name="x" /> y=<variable name="y" /> z=<variable name="z" /></output>
|
|
24
|
+
|
|
25
|
+
<!-- First call -->
|
|
26
|
+
<first-sub x="$x" y="$y" />
|
|
27
|
+
|
|
28
|
+
<!-- Verify variables still exist after first call -->
|
|
29
|
+
<output>x=<variable name="x" /> y=<variable name="y" /> z=<variable name="z" /></output>
|
|
30
|
+
|
|
31
|
+
<!-- Second call - this would fail with the bug -->
|
|
32
|
+
<second-sub x="$x" y="$y" z="$z" />
|
|
33
|
+
|
|
34
|
+
<!-- Verify variables still exist after second call -->
|
|
35
|
+
<output>x=<variable name="x" /> y=<variable name="y" /> z=<variable name="z" /></output>
|
|
36
|
+
</dirac>
|