agency-lang 0.0.85 → 0.0.87
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/lib/backends/agencyGenerator.d.ts +3 -4
- package/dist/lib/backends/agencyGenerator.js +96 -47
- package/dist/lib/backends/agencyGenerator.test.js +8 -8
- package/dist/lib/backends/index.d.ts +1 -0
- package/dist/lib/backends/index.js +1 -0
- package/dist/lib/backends/sourceMap.d.ts +13 -0
- package/dist/lib/backends/sourceMap.js +18 -0
- package/dist/lib/backends/sourceMap.test.d.ts +1 -0
- package/dist/lib/backends/sourceMap.test.js +57 -0
- package/dist/lib/backends/typescriptBuilder.d.ts +27 -4
- package/dist/lib/backends/typescriptBuilder.integration.test.js +27 -1
- package/dist/lib/backends/typescriptBuilder.js +438 -235
- package/dist/lib/backends/typescriptGenerator/typeToString.js +10 -0
- package/dist/lib/backends/typescriptGenerator/typeToZodSchema.js +2 -0
- package/dist/lib/backends/typescriptGenerator.integration.test.js +1 -1
- package/dist/lib/cli/bundle.d.ts +1 -0
- package/dist/lib/cli/bundle.js +58 -0
- package/dist/lib/cli/bundle.test.d.ts +1 -0
- package/dist/lib/cli/bundle.test.js +74 -0
- package/dist/lib/cli/commands.d.ts +1 -1
- package/dist/lib/cli/commands.js +11 -10
- package/dist/lib/cli/debug.d.ts +7 -0
- package/dist/lib/cli/debug.js +166 -0
- package/dist/lib/cli/definition.d.ts +22 -0
- package/dist/lib/cli/definition.js +66 -0
- package/dist/lib/cli/definition.test.d.ts +1 -0
- package/dist/lib/cli/definition.test.js +145 -0
- package/dist/lib/cli/doc.d.ts +2 -0
- package/dist/lib/cli/doc.js +117 -0
- package/dist/lib/cli/doc.test.d.ts +1 -0
- package/dist/lib/cli/doc.test.js +133 -0
- package/dist/lib/cli/test.d.ts +2 -2
- package/dist/lib/cli/test.js +268 -155
- package/dist/lib/cli/util.d.ts +28 -15
- package/dist/lib/cli/util.js +79 -16
- package/dist/lib/config.d.ts +12 -2
- package/dist/lib/config.js +1 -36
- package/dist/lib/debugger/debuggerState.d.ts +49 -0
- package/dist/lib/debugger/debuggerState.js +112 -0
- package/dist/lib/debugger/debuggerState.test.d.ts +1 -0
- package/dist/lib/debugger/debuggerState.test.js +115 -0
- package/dist/lib/debugger/driver.d.ts +60 -0
- package/dist/lib/debugger/driver.js +505 -0
- package/dist/lib/debugger/driver.test.d.ts +1 -0
- package/dist/lib/debugger/driver.test.js +762 -0
- package/dist/lib/debugger/testHelpers.d.ts +29 -0
- package/dist/lib/debugger/testHelpers.js +96 -0
- package/dist/lib/debugger/thread.test.d.ts +1 -0
- package/dist/lib/debugger/thread.test.js +84 -0
- package/dist/lib/debugger/trace.test.d.ts +1 -0
- package/dist/lib/debugger/trace.test.js +75 -0
- package/dist/lib/debugger/types.d.ts +61 -0
- package/dist/lib/debugger/types.js +1 -0
- package/dist/lib/debugger/ui.d.ts +54 -0
- package/dist/lib/debugger/ui.js +741 -0
- package/dist/lib/debugger/uiState.d.ts +86 -0
- package/dist/lib/debugger/uiState.js +244 -0
- package/dist/lib/debugger/uiState.test.d.ts +1 -0
- package/dist/lib/debugger/uiState.test.js +251 -0
- package/dist/lib/debugger/util.d.ts +6 -0
- package/dist/lib/debugger/util.js +133 -0
- package/dist/lib/debugger/util.test.d.ts +1 -0
- package/dist/lib/debugger/util.test.js +164 -0
- package/dist/lib/importPaths.d.ts +74 -0
- package/dist/lib/importPaths.js +239 -0
- package/dist/lib/importPaths.test.d.ts +1 -0
- package/dist/lib/importPaths.test.js +237 -0
- package/dist/lib/ir/audit.js +3 -23
- package/dist/lib/ir/audit.test.js +4 -9
- package/dist/lib/ir/builders.d.ts +48 -16
- package/dist/lib/ir/builders.js +44 -16
- package/dist/lib/ir/prettyPrint.js +47 -147
- package/dist/lib/ir/prettyPrint.test.js +0 -77
- package/dist/lib/ir/tsIR.d.ts +50 -74
- package/dist/lib/parser.d.ts +1 -1
- package/dist/lib/parser.js +18 -8
- package/dist/lib/parser.test.js +9 -94
- package/dist/lib/parsers/access.js +6 -4
- package/dist/lib/parsers/access.test.js +24 -24
- package/dist/lib/parsers/assignment.test.js +109 -8
- package/dist/lib/parsers/binop.js +14 -56
- package/dist/lib/parsers/binop.test.js +20 -20
- package/dist/lib/parsers/blockArgument.d.ts +3 -0
- package/dist/lib/parsers/blockArgument.js +28 -0
- package/dist/lib/parsers/blockArgument.test.d.ts +1 -0
- package/dist/lib/parsers/blockArgument.test.js +118 -0
- package/dist/lib/parsers/body.test.js +1 -1
- package/dist/lib/parsers/comment.js +2 -2
- package/dist/lib/parsers/comment.test.js +1 -1
- package/dist/lib/parsers/dataStructures.js +6 -7
- package/dist/lib/parsers/dataStructures.test.js +3 -3
- package/dist/lib/parsers/debuggerStatement.d.ts +3 -0
- package/dist/lib/parsers/debuggerStatement.js +12 -0
- package/dist/lib/parsers/debuggerStatement.test.d.ts +1 -0
- package/dist/lib/parsers/debuggerStatement.test.js +45 -0
- package/dist/lib/parsers/expression.d.ts +3 -0
- package/dist/lib/parsers/expression.js +121 -0
- package/dist/lib/parsers/expression.test.d.ts +1 -0
- package/dist/lib/parsers/expression.test.js +299 -0
- package/dist/lib/parsers/forLoop.test.js +1 -1
- package/dist/lib/parsers/function.d.ts +5 -2
- package/dist/lib/parsers/function.js +65 -30
- package/dist/lib/parsers/function.test.js +223 -154
- package/dist/lib/parsers/functionCall.js +8 -8
- package/dist/lib/parsers/functionCall.test.js +132 -7
- package/dist/lib/parsers/handleBlock.test.js +1 -1
- package/dist/lib/parsers/ifElse.test.js +1 -1
- package/dist/lib/parsers/importStatement.js +22 -8
- package/dist/lib/parsers/importStatement.test.js +27 -27
- package/dist/lib/parsers/keyword.test.js +1 -1
- package/dist/lib/parsers/literals.d.ts +4 -3
- package/dist/lib/parsers/literals.js +15 -19
- package/dist/lib/parsers/literals.test.js +63 -8
- package/dist/lib/parsers/loc.d.ts +9 -0
- package/dist/lib/parsers/loc.js +30 -0
- package/dist/lib/parsers/matchBlock.d.ts +1 -1
- package/dist/lib/parsers/matchBlock.js +4 -7
- package/dist/lib/parsers/matchBlock.test.js +3 -3
- package/dist/lib/parsers/multiLineComment.test.js +1 -1
- package/dist/lib/parsers/parserUtils.test.js +2 -2
- package/dist/lib/parsers/returnStatement.js +5 -7
- package/dist/lib/parsers/returnStatement.test.js +1 -1
- package/dist/lib/parsers/skill.test.js +1 -1
- package/dist/lib/parsers/specialVar.js +2 -4
- package/dist/lib/parsers/specialVar.test.js +1 -1
- package/dist/lib/parsers/tools.test.js +1 -1
- package/dist/lib/parsers/typeHints.d.ts +2 -2
- package/dist/lib/parsers/typeHints.js +23 -7
- package/dist/lib/parsers/typeHints.test.js +62 -378
- package/dist/lib/parsers/utils.d.ts +1 -1
- package/dist/lib/parsers/vitest.setup.d.ts +9 -0
- package/dist/lib/parsers/vitest.setup.js +53 -0
- package/dist/lib/parsers/whileLoop.test.js +1 -1
- package/dist/lib/preprocessors/importResolver.d.ts +0 -8
- package/dist/lib/preprocessors/importResolver.js +41 -7
- package/dist/lib/preprocessors/importResolver.test.js +23 -6
- package/dist/lib/preprocessors/typescriptPreprocessor.config.test.js +1 -2
- package/dist/lib/preprocessors/typescriptPreprocessor.core.test.js +0 -20
- package/dist/lib/preprocessors/typescriptPreprocessor.d.ts +1 -5
- package/dist/lib/preprocessors/typescriptPreprocessor.integration.test.js +1 -1
- package/dist/lib/preprocessors/typescriptPreprocessor.js +125 -34
- package/dist/lib/programInfo.d.ts +6 -6
- package/dist/lib/programInfo.js +23 -11
- package/dist/lib/programInfo.test.js +2 -114
- package/dist/lib/runtime/audit.d.ts +14 -3
- package/dist/lib/runtime/builtinTools.d.ts +0 -90
- package/dist/lib/runtime/builtinTools.js +0 -65
- package/dist/lib/runtime/builtins.d.ts +0 -15
- package/dist/lib/runtime/builtins.js +0 -55
- package/dist/lib/runtime/checkpoint.js +6 -2
- package/dist/lib/runtime/checkpoint.test.js +14 -4
- package/dist/lib/runtime/debugger.d.ts +9 -0
- package/dist/lib/runtime/debugger.js +86 -0
- package/dist/lib/runtime/debugger.test.d.ts +1 -0
- package/dist/lib/runtime/debugger.test.js +161 -0
- package/dist/lib/runtime/hooks.d.ts +2 -0
- package/dist/lib/runtime/index.d.ts +10 -3
- package/dist/lib/runtime/index.js +9 -3
- package/dist/lib/runtime/interrupts.d.ts +13 -5
- package/dist/lib/runtime/interrupts.js +100 -30
- package/dist/lib/runtime/isDebugger.test.d.ts +1 -0
- package/dist/lib/runtime/isDebugger.test.js +24 -0
- package/dist/lib/runtime/prompt.js +9 -3
- package/dist/lib/runtime/rewind.d.ts +20 -0
- package/dist/lib/runtime/rewind.js +73 -0
- package/dist/lib/runtime/runner.d.ts +73 -0
- package/dist/lib/runtime/runner.js +368 -0
- package/dist/lib/runtime/runner.test.d.ts +1 -0
- package/dist/lib/runtime/runner.test.js +423 -0
- package/dist/lib/runtime/state/checkpointStore.d.ts +81 -8
- package/dist/lib/runtime/state/checkpointStore.js +256 -17
- package/dist/lib/runtime/state/checkpointStore.test.js +504 -30
- package/dist/lib/runtime/state/context.d.ts +5 -0
- package/dist/lib/runtime/state/context.js +19 -2
- package/dist/lib/runtime/state/context.test.d.ts +1 -0
- package/dist/lib/runtime/state/context.test.js +20 -0
- package/dist/lib/runtime/state/globalStore.d.ts +4 -0
- package/dist/lib/runtime/state/globalStore.js +9 -0
- package/dist/lib/runtime/state/schemas.d.ts +86 -0
- package/dist/lib/runtime/state/schemas.js +50 -0
- package/dist/lib/runtime/state/sourceLocation.d.ts +6 -0
- package/dist/lib/runtime/state/sourceLocation.js +1 -0
- package/dist/lib/runtime/state/stateStack.d.ts +21 -0
- package/dist/lib/runtime/state/stateStack.js +55 -3
- package/dist/lib/runtime/state/stateStack.test.js +27 -0
- package/dist/lib/runtime/trace/canonicalize.d.ts +1 -0
- package/dist/lib/runtime/trace/canonicalize.js +17 -0
- package/dist/lib/runtime/trace/canonicalize.test.d.ts +1 -0
- package/dist/lib/runtime/trace/canonicalize.test.js +39 -0
- package/dist/lib/runtime/trace/contentAddressableStore.d.ts +23 -0
- package/dist/lib/runtime/trace/contentAddressableStore.js +94 -0
- package/dist/lib/runtime/trace/contentAddressableStore.test.d.ts +1 -0
- package/dist/lib/runtime/trace/contentAddressableStore.test.js +88 -0
- package/dist/lib/runtime/trace/traceReader.d.ts +10 -0
- package/dist/lib/runtime/trace/traceReader.js +67 -0
- package/dist/lib/runtime/trace/traceReader.test.d.ts +1 -0
- package/dist/lib/runtime/trace/traceReader.test.js +150 -0
- package/dist/lib/runtime/trace/traceWriter.d.ts +9 -0
- package/dist/lib/runtime/trace/traceWriter.js +34 -0
- package/dist/lib/runtime/trace/traceWriter.test.d.ts +1 -0
- package/dist/lib/runtime/trace/traceWriter.test.js +103 -0
- package/dist/lib/runtime/trace/types.d.ts +42 -0
- package/dist/lib/runtime/trace/types.js +4 -0
- package/dist/lib/runtime/types.d.ts +4 -1
- package/dist/lib/statelogClient.d.ts +2 -27
- package/dist/lib/statelogClient.js +8 -135
- package/dist/lib/symbolTable.d.ts +4 -1
- package/dist/lib/symbolTable.js +10 -6
- package/dist/lib/symbolTable.test.js +5 -4
- package/dist/lib/templates/backends/agency/template.d.ts +6 -0
- package/dist/lib/templates/backends/agency/template.js +11 -0
- package/dist/lib/templates/backends/typescriptGenerator/blockSetup.d.ts +12 -0
- package/dist/lib/templates/backends/typescriptGenerator/blockSetup.js +21 -0
- package/dist/lib/templates/backends/typescriptGenerator/debugger.d.ts +11 -0
- package/dist/lib/templates/backends/typescriptGenerator/debugger.js +25 -0
- package/dist/lib/templates/backends/typescriptGenerator/imports.d.ts +1 -1
- package/dist/lib/templates/backends/typescriptGenerator/imports.js +18 -51
- package/dist/lib/templates/backends/typescriptGenerator/interruptAssignment.d.ts +5 -3
- package/dist/lib/templates/backends/typescriptGenerator/interruptAssignment.js +14 -6
- package/dist/lib/templates/backends/typescriptGenerator/interruptReturn.d.ts +4 -1
- package/dist/lib/templates/backends/typescriptGenerator/interruptReturn.js +11 -16
- package/dist/lib/templates/backends/typescriptGenerator/rewindCheckpoint.d.ts +11 -0
- package/dist/lib/templates/backends/typescriptGenerator/rewindCheckpoint.js +32 -0
- package/dist/lib/templates/backends/typescriptGenerator/traceSetup.d.ts +7 -0
- package/dist/lib/templates/backends/typescriptGenerator/traceSetup.js +12 -0
- package/dist/lib/templates/cli/evaluate.d.ts +2 -1
- package/dist/lib/templates/cli/evaluate.js +1 -1
- package/dist/lib/templates/cli/judgeEvaluate.d.ts +2 -1
- package/dist/lib/templates/cli/judgeEvaluate.js +1 -1
- package/dist/lib/typeChecker.js +17 -12
- package/dist/lib/typeChecker.test.js +20 -39
- package/dist/lib/types/access.d.ts +4 -3
- package/dist/lib/types/awaitPending.d.ts +2 -1
- package/dist/lib/types/base.d.ts +9 -0
- package/dist/lib/types/base.js +1 -0
- package/dist/lib/types/binop.d.ts +7 -9
- package/dist/lib/types/binop.js +1 -0
- package/dist/lib/types/blockArgument.d.ts +8 -0
- package/dist/lib/types/blockArgument.js +1 -0
- package/dist/lib/types/dataStructures.d.ts +12 -8
- package/dist/lib/types/debuggerStatement.d.ts +6 -0
- package/dist/lib/types/debuggerStatement.js +1 -0
- package/dist/lib/types/forLoop.d.ts +4 -4
- package/dist/lib/types/function.d.ts +11 -7
- package/dist/lib/types/graphNode.d.ts +2 -1
- package/dist/lib/types/handleBlock.d.ts +2 -1
- package/dist/lib/types/ifElse.d.ts +4 -5
- package/dist/lib/types/importStatement.d.ts +7 -4
- package/dist/lib/types/importStatement.js +6 -0
- package/dist/lib/types/keyword.d.ts +2 -1
- package/dist/lib/types/literals.d.ts +13 -10
- package/dist/lib/types/matchBlock.d.ts +6 -10
- package/dist/lib/types/messageThread.d.ts +2 -1
- package/dist/lib/types/returnStatement.d.ts +4 -6
- package/dist/lib/types/sentinel.d.ts +11 -0
- package/dist/lib/types/sentinel.js +1 -0
- package/dist/lib/types/skill.d.ts +2 -1
- package/dist/lib/types/specialVar.d.ts +4 -6
- package/dist/lib/types/tools.d.ts +2 -1
- package/dist/lib/types/typeHints.d.ts +10 -6
- package/dist/lib/types/whileLoop.d.ts +4 -5
- package/dist/lib/types.d.ts +25 -12
- package/dist/lib/types.js +5 -0
- package/dist/lib/utils/markdown.d.ts +6 -0
- package/dist/lib/utils/markdown.js +21 -0
- package/dist/lib/utils/markdown.test.d.ts +1 -0
- package/dist/lib/utils/markdown.test.js +39 -0
- package/dist/lib/utils/node.d.ts +7 -5
- package/dist/lib/utils/node.js +92 -32
- package/dist/lib/utils.d.ts +1 -0
- package/dist/lib/utils.js +4 -0
- package/dist/lib/version.d.ts +1 -0
- package/dist/lib/version.js +1 -0
- package/dist/scripts/agency.js +82 -44
- package/dist/scripts/regenerate-fixtures.js +18 -60
- package/package.json +12 -6
- package/stdlib/_builtins.js +101 -0
- package/stdlib/_math.js +9 -0
- package/stdlib/clipboard.agency +15 -0
- package/stdlib/index.agency +115 -0
- package/stdlib/index.js +1350 -0
- package/stdlib/lib/clipboard.js +29 -0
- package/stdlib/lib/process.js +29 -0
- package/stdlib/lib/speech.js +69 -0
- package/stdlib/lib/system.js +29 -0
- package/stdlib/lib/utils.js +51 -0
- package/stdlib/math.agency +13 -0
- package/stdlib/math.js +389 -0
- package/stdlib/process.agency +25 -0
- package/stdlib/speech.agency +15 -0
- package/stdlib/system.agency +8 -0
- package/dist/lib/cli/remoteRun.d.ts +0 -3
- package/dist/lib/cli/remoteRun.js +0 -35
- package/dist/lib/cli/upload.d.ts +0 -3
- package/dist/lib/cli/upload.js +0 -50
- package/dist/lib/templates/backends/typescriptGenerator/forSteps.d.ts +0 -20
- package/dist/lib/templates/backends/typescriptGenerator/forSteps.js +0 -32
- package/dist/lib/templates/backends/typescriptGenerator/handleSteps.d.ts +0 -16
- package/dist/lib/templates/backends/typescriptGenerator/handleSteps.js +0 -22
- package/dist/lib/templates/backends/typescriptGenerator/ifStepsBranchDispatch.d.ts +0 -17
- package/dist/lib/templates/backends/typescriptGenerator/ifStepsBranchDispatch.js +0 -18
- package/dist/lib/templates/backends/typescriptGenerator/ifStepsCondbranch.d.ts +0 -17
- package/dist/lib/templates/backends/typescriptGenerator/ifStepsCondbranch.js +0 -26
- package/dist/lib/templates/backends/typescriptGenerator/substepBlock.d.ts +0 -10
- package/dist/lib/templates/backends/typescriptGenerator/substepBlock.js +0 -12
- package/dist/lib/templates/backends/typescriptGenerator/threadSteps.d.ts +0 -16
- package/dist/lib/templates/backends/typescriptGenerator/threadSteps.js +0 -21
- package/dist/lib/templates/backends/typescriptGenerator/whileSteps.d.ts +0 -16
- package/dist/lib/templates/backends/typescriptGenerator/whileSteps.js +0 -29
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { SpecialVar } from "../types/specialVar.js";
|
|
2
|
-
import { AgencyComment, AgencyMultiLineComment, AgencyNode, AgencyProgram, Assignment, Literal, NewLine, Scope, TypeAlias,
|
|
2
|
+
import { AgencyComment, AgencyMultiLineComment, AgencyNode, AgencyProgram, Assignment, DebuggerStatement, Literal, NewLine, Scope, TypeAlias, VariableType } from "../types.js";
|
|
3
3
|
import { AccessChainElement, ValueAccess } from "../types/access.js";
|
|
4
4
|
import { AgencyArray, AgencyObject } from "../types/dataStructures.js";
|
|
5
5
|
import { FunctionCall, FunctionDefinition } from "../types/function.js";
|
|
@@ -18,7 +18,6 @@ import { BinOpArgument, BinOpExpression, Operator } from "../types/binop.js";
|
|
|
18
18
|
import { Keyword } from "../types/keyword.js";
|
|
19
19
|
import { HandleBlock } from "../types/handleBlock.js";
|
|
20
20
|
export declare class AgencyGenerator {
|
|
21
|
-
protected typeHints: TypeHintMap;
|
|
22
21
|
protected graphNodes: GraphNodeDefinition[];
|
|
23
22
|
protected generatedStatements: string[];
|
|
24
23
|
protected generatedTypeAliases: string[];
|
|
@@ -48,7 +47,7 @@ export declare class AgencyGenerator {
|
|
|
48
47
|
protected postprocess(): string;
|
|
49
48
|
protected collectFunctionSignature(node: FunctionDefinition): void;
|
|
50
49
|
protected processGraphNodeName(node: GraphNodeDefinition): void;
|
|
51
|
-
|
|
50
|
+
processNode(node: AgencyNode): string;
|
|
52
51
|
protected needsParensLeft(child: BinOpArgument, parentOp: Operator): boolean;
|
|
53
52
|
protected needsParensRight(child: BinOpArgument, parentOp: Operator): boolean;
|
|
54
53
|
protected startScope(scope: Scope): void;
|
|
@@ -63,7 +62,6 @@ export declare class AgencyGenerator {
|
|
|
63
62
|
private stringifyProp;
|
|
64
63
|
protected aliasedTypeToString(aliasedType: VariableType): string;
|
|
65
64
|
protected processTypeAlias(node: TypeAlias): string;
|
|
66
|
-
protected processTypeHint(node: TypeHint): string;
|
|
67
65
|
protected processAssignment(node: Assignment): string;
|
|
68
66
|
protected generateLiteral(literal: Literal): string;
|
|
69
67
|
private generateStringLiteral;
|
|
@@ -80,6 +78,7 @@ export declare class AgencyGenerator {
|
|
|
80
78
|
protected processWhileLoop(node: WhileLoop): string;
|
|
81
79
|
protected processIfElse(node: IfElse): string;
|
|
82
80
|
protected processReturnStatement(node: ReturnStatement): string;
|
|
81
|
+
protected processDebuggerStatement(node: DebuggerStatement): string;
|
|
83
82
|
protected processComment(node: AgencyComment): string;
|
|
84
83
|
protected processMultiLineComment(node: AgencyMultiLineComment): string;
|
|
85
84
|
protected processImportStatement(node: ImportStatement): string;
|
|
@@ -3,7 +3,6 @@ import { mergeDeep } from "../utils.js";
|
|
|
3
3
|
import { PRECEDENCE, } from "../types/binop.js";
|
|
4
4
|
import { expressionToString } from "../utils/node.js";
|
|
5
5
|
export class AgencyGenerator {
|
|
6
|
-
typeHints = {};
|
|
7
6
|
graphNodes = [];
|
|
8
7
|
generatedStatements = [];
|
|
9
8
|
generatedTypeAliases = [];
|
|
@@ -35,19 +34,13 @@ export class AgencyGenerator {
|
|
|
35
34
|
this.processTypeAlias(node);
|
|
36
35
|
}
|
|
37
36
|
}
|
|
38
|
-
// Pass 2: Collect all
|
|
39
|
-
for (const node of program.nodes) {
|
|
40
|
-
if (node.type === "typeHint") {
|
|
41
|
-
this.processTypeHint(node);
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
// Pass 3: Collect all node names
|
|
37
|
+
// Pass 2: Collect all node names
|
|
45
38
|
for (const node of program.nodes) {
|
|
46
39
|
if (node.type === "graphNode") {
|
|
47
40
|
this.processGraphNodeName(node);
|
|
48
41
|
}
|
|
49
42
|
}
|
|
50
|
-
// Pass
|
|
43
|
+
// Pass 3: Collect all node and tool imports
|
|
51
44
|
for (const node of program.nodes) {
|
|
52
45
|
if (node.type === "importNodeStatement") {
|
|
53
46
|
this.importedNodes.push(node);
|
|
@@ -56,7 +49,7 @@ export class AgencyGenerator {
|
|
|
56
49
|
this.importedTools.push(node);
|
|
57
50
|
}
|
|
58
51
|
}
|
|
59
|
-
// Pass
|
|
52
|
+
// Pass 4: Generate code for tools
|
|
60
53
|
for (const node of program.nodes) {
|
|
61
54
|
if (node.type === "function") {
|
|
62
55
|
this.generatedStatements.push(this.processTool(node));
|
|
@@ -64,10 +57,33 @@ export class AgencyGenerator {
|
|
|
64
57
|
}
|
|
65
58
|
}
|
|
66
59
|
this.preprocessAST();
|
|
67
|
-
//
|
|
60
|
+
// Types that should have a blank line before/after them at the top level
|
|
61
|
+
const BLOCK_TYPES = new Set([
|
|
62
|
+
"graphNode", "function", "typeAlias",
|
|
63
|
+
]);
|
|
64
|
+
const NO_SPACE_TYPES = new Set([
|
|
65
|
+
"comment", "multiLineComment"
|
|
66
|
+
]);
|
|
67
|
+
// Pass 5: Process all nodes and generate code
|
|
68
|
+
const stmtPairs = [];
|
|
68
69
|
for (const node of program.nodes) {
|
|
69
70
|
const result = this.processNode(node);
|
|
70
|
-
|
|
71
|
+
if (result !== "") {
|
|
72
|
+
stmtPairs.push({ type: node.type, code: result });
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
// Join top-level statements: blank line between block declarations,
|
|
76
|
+
// single newline between simple statements
|
|
77
|
+
const stmtLines = [];
|
|
78
|
+
for (let i = 0; i < stmtPairs.length; i++) {
|
|
79
|
+
if (i > 0) {
|
|
80
|
+
const prev = stmtPairs[i - 1];
|
|
81
|
+
const curr = stmtPairs[i];
|
|
82
|
+
if (BLOCK_TYPES.has(prev.type) || (BLOCK_TYPES.has(curr.type) && !NO_SPACE_TYPES.has(prev.type))) {
|
|
83
|
+
stmtLines.push(""); // blank line
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
stmtLines.push(stmtPairs[i].code);
|
|
71
87
|
}
|
|
72
88
|
const output = [];
|
|
73
89
|
this.addIfNonEmpty(this.preprocess(), output);
|
|
@@ -75,7 +91,7 @@ export class AgencyGenerator {
|
|
|
75
91
|
this.addIfNonEmpty(this.generateImports(), output);
|
|
76
92
|
this.addIfNonEmpty(this.generateBuiltins(), output);
|
|
77
93
|
output.push(...this.generatedTypeAliases);
|
|
78
|
-
output.push(
|
|
94
|
+
output.push(stmtLines.join("\n"));
|
|
79
95
|
this.addIfNonEmpty(this.postprocess(), output);
|
|
80
96
|
return {
|
|
81
97
|
output: output.join("\n"),
|
|
@@ -105,8 +121,6 @@ export class AgencyGenerator {
|
|
|
105
121
|
processGraphNodeName(node) { }
|
|
106
122
|
processNode(node) {
|
|
107
123
|
switch (node.type) {
|
|
108
|
-
case "typeHint":
|
|
109
|
-
return this.processTypeHint(node);
|
|
110
124
|
case "typeAlias":
|
|
111
125
|
return this.processTypeAlias(node);
|
|
112
126
|
case "assignment":
|
|
@@ -128,9 +142,12 @@ export class AgencyGenerator {
|
|
|
128
142
|
case "string":
|
|
129
143
|
case "variableName":
|
|
130
144
|
case "boolean":
|
|
145
|
+
case "null":
|
|
131
146
|
return this.generateLiteral(node);
|
|
132
147
|
case "returnStatement":
|
|
133
148
|
return this.processReturnStatement(node);
|
|
149
|
+
case "debuggerStatement":
|
|
150
|
+
return this.processDebuggerStatement(node);
|
|
134
151
|
case "agencyArray":
|
|
135
152
|
return this.processAgencyArray(node);
|
|
136
153
|
case "agencyObject":
|
|
@@ -195,8 +212,8 @@ export class AgencyGenerator {
|
|
|
195
212
|
}
|
|
196
213
|
isImportedTool(functionName) {
|
|
197
214
|
return this.importedTools
|
|
198
|
-
.
|
|
199
|
-
.
|
|
215
|
+
.flatMap((node) => node.importedTools)
|
|
216
|
+
.flatMap((n) => n.importedNames)
|
|
200
217
|
.includes(functionName);
|
|
201
218
|
}
|
|
202
219
|
isAgencyFunction(functionName, context) {
|
|
@@ -261,11 +278,6 @@ export class AgencyGenerator {
|
|
|
261
278
|
const aliasedTypeStr = this.aliasedTypeToString(node.aliasedType);
|
|
262
279
|
return this.indentStr(`type ${node.aliasName} = ${aliasedTypeStr}`);
|
|
263
280
|
}
|
|
264
|
-
processTypeHint(node) {
|
|
265
|
-
this.typeHints[node.variableName] = node.variableType;
|
|
266
|
-
const typeStr = variableTypeToString(node.variableType, this.typeAliases);
|
|
267
|
-
return this.indentStr(`${node.variableName} :: ${typeStr}`);
|
|
268
|
-
}
|
|
269
281
|
// Assignment and literals
|
|
270
282
|
processAssignment(node) {
|
|
271
283
|
const chainStr = node.accessChain
|
|
@@ -274,9 +286,10 @@ export class AgencyGenerator {
|
|
|
274
286
|
const varName = node.typeHint
|
|
275
287
|
? `${node.variableName}${chainStr}: ${variableTypeToString(node.typeHint, this.typeAliases)}`
|
|
276
288
|
: `${node.variableName}${chainStr}`;
|
|
277
|
-
const
|
|
289
|
+
const sharedPrefix = node.shared ? "shared " : "";
|
|
290
|
+
const declPrefix = node.declKind ? `${node.declKind} ` : "";
|
|
278
291
|
let valueCode = this.processNode(node.value).trim();
|
|
279
|
-
return this.indentStr(`${
|
|
292
|
+
return this.indentStr(`${sharedPrefix}${declPrefix}${varName} = ${valueCode}`);
|
|
280
293
|
}
|
|
281
294
|
generateLiteral(literal) {
|
|
282
295
|
switch (literal.type) {
|
|
@@ -290,6 +303,8 @@ export class AgencyGenerator {
|
|
|
290
303
|
return this.generateMultiLineStringLiteral(literal);
|
|
291
304
|
case "boolean":
|
|
292
305
|
return literal.value ? "true" : "false";
|
|
306
|
+
case "null":
|
|
307
|
+
return "null";
|
|
293
308
|
default:
|
|
294
309
|
return "";
|
|
295
310
|
}
|
|
@@ -328,12 +343,16 @@ export class AgencyGenerator {
|
|
|
328
343
|
const { functionName, body, parameters } = node;
|
|
329
344
|
const params = parameters
|
|
330
345
|
.map((p) => {
|
|
346
|
+
const prefix = p.variadic ? "..." : "";
|
|
347
|
+
const defaultSuffix = p.defaultValue
|
|
348
|
+
? ` = ${this.processNode(p.defaultValue).trim()}`
|
|
349
|
+
: "";
|
|
331
350
|
if (p.typeHint) {
|
|
332
351
|
const typeStr = variableTypeToString(p.typeHint, this.typeAliases);
|
|
333
|
-
return `${p.name}: ${typeStr}`;
|
|
352
|
+
return `${prefix}${p.name}: ${typeStr}${defaultSuffix}`;
|
|
334
353
|
}
|
|
335
354
|
else {
|
|
336
|
-
return p.name
|
|
355
|
+
return `${prefix}${p.name}${defaultSuffix}`;
|
|
337
356
|
}
|
|
338
357
|
})
|
|
339
358
|
.join(", ");
|
|
@@ -341,14 +360,8 @@ export class AgencyGenerator {
|
|
|
341
360
|
? ": " + variableTypeToString(node.returnType, this.typeAliases)
|
|
342
361
|
: "";
|
|
343
362
|
let safePrefix = node.safe ? "safe " : "";
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
asyncPrefix = "async ";
|
|
347
|
-
}
|
|
348
|
-
else if (node.async === false) {
|
|
349
|
-
asyncPrefix = "sync ";
|
|
350
|
-
}
|
|
351
|
-
let result = this.indentStr(`${safePrefix}${asyncPrefix}def ${functionName}(${params})${returnTypeStr} {\n`);
|
|
363
|
+
const exportPrefix = node.exported ? "export " : "";
|
|
364
|
+
let result = this.indentStr(`${exportPrefix}${safePrefix}def ${functionName}(${params})${returnTypeStr} {\n`);
|
|
352
365
|
this.increaseIndent();
|
|
353
366
|
if (node.docString) {
|
|
354
367
|
const docLines = [`"""`, ...node.docString.value.split("\n"), `"""`];
|
|
@@ -359,7 +372,7 @@ export class AgencyGenerator {
|
|
|
359
372
|
for (const stmt of body) {
|
|
360
373
|
lines.push(this.processNode(stmt));
|
|
361
374
|
}
|
|
362
|
-
const bodyCode = lines.join("").trimEnd() + "\n";
|
|
375
|
+
const bodyCode = lines.filter(s => s !== "").join("\n").trimEnd() + "\n";
|
|
363
376
|
result += bodyCode;
|
|
364
377
|
this.decreaseIndent();
|
|
365
378
|
result += this.indentStr(`}`);
|
|
@@ -371,6 +384,12 @@ export class AgencyGenerator {
|
|
|
371
384
|
}
|
|
372
385
|
generateFunctionCallExpression(node, context) {
|
|
373
386
|
const args = node.arguments.map((arg) => {
|
|
387
|
+
if (arg.type === "namedArgument") {
|
|
388
|
+
return `${arg.name}: ${this.processNode(arg.value).trim()}`;
|
|
389
|
+
}
|
|
390
|
+
if (arg.type === "splat") {
|
|
391
|
+
return `...${this.processNode(arg.value).trim()}`;
|
|
392
|
+
}
|
|
374
393
|
return this.processNode(arg).trim();
|
|
375
394
|
});
|
|
376
395
|
let asyncPrefix = "";
|
|
@@ -380,7 +399,26 @@ export class AgencyGenerator {
|
|
|
380
399
|
else if (node.async === false) {
|
|
381
400
|
asyncPrefix = "await ";
|
|
382
401
|
}
|
|
383
|
-
|
|
402
|
+
let result = `${asyncPrefix}${node.functionName}(${args.join(", ")})`;
|
|
403
|
+
if (node.block) {
|
|
404
|
+
const block = node.block;
|
|
405
|
+
let asClause = "as ";
|
|
406
|
+
if (block.params.length === 1) {
|
|
407
|
+
asClause = `as ${block.params[0].name} `;
|
|
408
|
+
}
|
|
409
|
+
else if (block.params.length > 1) {
|
|
410
|
+
asClause = `as (${block.params.map((p) => p.name).join(", ")}) `;
|
|
411
|
+
}
|
|
412
|
+
this.increaseIndent();
|
|
413
|
+
const bodyLines = [];
|
|
414
|
+
for (const stmt of block.body) {
|
|
415
|
+
bodyLines.push(this.processNode(stmt));
|
|
416
|
+
}
|
|
417
|
+
this.decreaseIndent();
|
|
418
|
+
const bodyStr = bodyLines.filter((s) => s !== "").join("\n").trimEnd() + "\n";
|
|
419
|
+
result += ` ${asClause}{\n${bodyStr}${this.indentStr("}")}`;
|
|
420
|
+
}
|
|
421
|
+
return result;
|
|
384
422
|
}
|
|
385
423
|
// Data structures
|
|
386
424
|
processAgencyArray(node) {
|
|
@@ -459,9 +497,11 @@ export class AgencyGenerator {
|
|
|
459
497
|
: node.itemVar;
|
|
460
498
|
let result = this.indentStr(`for (${vars} in ${iterableCode}) {\n`);
|
|
461
499
|
this.increaseIndent();
|
|
500
|
+
const lines = [];
|
|
462
501
|
for (const stmt of node.body) {
|
|
463
|
-
|
|
502
|
+
lines.push(this.processNode(stmt));
|
|
464
503
|
}
|
|
504
|
+
result += lines.filter(s => s !== "").join("\n").trimEnd() + "\n";
|
|
465
505
|
this.decreaseIndent();
|
|
466
506
|
result += this.indentStr(`}`);
|
|
467
507
|
return result;
|
|
@@ -470,9 +510,11 @@ export class AgencyGenerator {
|
|
|
470
510
|
const conditionCode = this.processNode(node.condition).trim();
|
|
471
511
|
let result = this.indentStr(`while (${conditionCode}) {\n`);
|
|
472
512
|
this.increaseIndent();
|
|
513
|
+
const lines = [];
|
|
473
514
|
for (const stmt of node.body) {
|
|
474
|
-
|
|
515
|
+
lines.push(this.processNode(stmt));
|
|
475
516
|
}
|
|
517
|
+
result += lines.filter(s => s !== "").join("\n").trimEnd() + "\n";
|
|
476
518
|
this.decreaseIndent();
|
|
477
519
|
result += this.indentStr(`}`);
|
|
478
520
|
return result;
|
|
@@ -487,7 +529,7 @@ export class AgencyGenerator {
|
|
|
487
529
|
bodyLines.push(this.processNode(stmt));
|
|
488
530
|
}
|
|
489
531
|
this.decreaseIndent();
|
|
490
|
-
lines.push(bodyLines.join("").trimEnd() + "\n");
|
|
532
|
+
lines.push(bodyLines.filter(s => s !== "").join("\n").trimEnd() + "\n");
|
|
491
533
|
if (node.elseBody && node.elseBody.length > 0) {
|
|
492
534
|
if (node.elseBody.length === 1 && node.elseBody[0].type === "ifElse") {
|
|
493
535
|
const elseIfCode = this.processIfElse(node.elseBody[0]);
|
|
@@ -502,7 +544,7 @@ export class AgencyGenerator {
|
|
|
502
544
|
elseBodyLines.push(this.processNode(stmt));
|
|
503
545
|
}
|
|
504
546
|
this.decreaseIndent();
|
|
505
|
-
lines.push(elseBodyLines.join("").trimEnd() + "\n");
|
|
547
|
+
lines.push(elseBodyLines.filter(s => s !== "").join("\n").trimEnd() + "\n");
|
|
506
548
|
}
|
|
507
549
|
}
|
|
508
550
|
lines.push(this.indentStr(`}`));
|
|
@@ -512,6 +554,9 @@ export class AgencyGenerator {
|
|
|
512
554
|
const valueCode = this.processNode(node.value).trim();
|
|
513
555
|
return this.indentStr(`return ${valueCode}`);
|
|
514
556
|
}
|
|
557
|
+
processDebuggerStatement(node) {
|
|
558
|
+
return this.indentStr(node.label ? `debugger(${JSON.stringify(node.label)})` : "debugger()");
|
|
559
|
+
}
|
|
515
560
|
// Utility methods
|
|
516
561
|
processComment(node) {
|
|
517
562
|
return this.indentStr(`//${node.content}`);
|
|
@@ -521,7 +566,10 @@ export class AgencyGenerator {
|
|
|
521
566
|
}
|
|
522
567
|
processImportStatement(node) {
|
|
523
568
|
const importedNames = node.importedNames.map((name) => this.processImportNameType(name));
|
|
524
|
-
const
|
|
569
|
+
const modulePath = node.modulePath.startsWith("std::")
|
|
570
|
+
? node.modulePath.replace(/\.agency$/, "")
|
|
571
|
+
: node.modulePath;
|
|
572
|
+
const str = this.indentStr(`import ${importedNames.join(", ")} from "${modulePath}"`);
|
|
525
573
|
return str;
|
|
526
574
|
}
|
|
527
575
|
processImportNameType(node) {
|
|
@@ -540,7 +588,8 @@ export class AgencyGenerator {
|
|
|
540
588
|
return `import node { ${node.importedNodes.join(", ")} } from "${node.agencyFile}"`;
|
|
541
589
|
}
|
|
542
590
|
processImportToolStatement(node) {
|
|
543
|
-
|
|
591
|
+
const toolNames = node.importedTools.flatMap((n) => n.importedNames);
|
|
592
|
+
return `import tool { ${toolNames.join(", ")} } from "${node.agencyFile}"`;
|
|
544
593
|
}
|
|
545
594
|
visibilityToString(vis) {
|
|
546
595
|
switch (vis) {
|
|
@@ -569,7 +618,7 @@ export class AgencyGenerator {
|
|
|
569
618
|
for (const stmt of body) {
|
|
570
619
|
lines.push(this.processNode(stmt));
|
|
571
620
|
}
|
|
572
|
-
const bodyCode = lines.join("").trimEnd() + "\n";
|
|
621
|
+
const bodyCode = lines.filter(s => s !== "").join("\n").trimEnd() + "\n";
|
|
573
622
|
result += bodyCode;
|
|
574
623
|
this.decreaseIndent();
|
|
575
624
|
result += this.indentStr(`}`);
|
|
@@ -585,7 +634,7 @@ export class AgencyGenerator {
|
|
|
585
634
|
return this.indentStr(`@${node.name} = ${this.processNode(node.value).trim()}`);
|
|
586
635
|
}
|
|
587
636
|
processNewLine(_node) {
|
|
588
|
-
return "
|
|
637
|
+
return "";
|
|
589
638
|
}
|
|
590
639
|
processMessageThread(node) {
|
|
591
640
|
this.increaseIndent();
|
|
@@ -594,7 +643,7 @@ export class AgencyGenerator {
|
|
|
594
643
|
bodyCodes.push(this.processNode(stmt));
|
|
595
644
|
}
|
|
596
645
|
this.decreaseIndent();
|
|
597
|
-
const bodyCodeStr = bodyCodes.join("");
|
|
646
|
+
const bodyCodeStr = bodyCodes.filter(s => s !== "").join("\n").trimEnd() + "\n";
|
|
598
647
|
const threadType = node.threadType;
|
|
599
648
|
return this.indentStr(`${threadType} {\n${bodyCodeStr}${this.indentStr("}")}`);
|
|
600
649
|
}
|
|
@@ -605,7 +654,7 @@ export class AgencyGenerator {
|
|
|
605
654
|
bodyCodes.push(this.processNode(stmt));
|
|
606
655
|
}
|
|
607
656
|
this.decreaseIndent();
|
|
608
|
-
const bodyCodeStr = bodyCodes.join("");
|
|
657
|
+
const bodyCodeStr = bodyCodes.filter(s => s !== "").join("\n").trimEnd() + "\n";
|
|
609
658
|
let handlerStr;
|
|
610
659
|
if (node.handler.kind === "inline") {
|
|
611
660
|
const paramStr = node.handler.param.typeHint
|
|
@@ -617,7 +666,7 @@ export class AgencyGenerator {
|
|
|
617
666
|
handlerBodyCodes.push(this.processNode(stmt));
|
|
618
667
|
}
|
|
619
668
|
this.decreaseIndent();
|
|
620
|
-
const handlerBodyStr = handlerBodyCodes.join("");
|
|
669
|
+
const handlerBodyStr = handlerBodyCodes.filter(s => s !== "").join("\n").trimEnd() + "\n";
|
|
621
670
|
handlerStr = `(${paramStr}) {\n${handlerBodyStr}${this.indentStr("}")}`;
|
|
622
671
|
}
|
|
623
672
|
else {
|
|
@@ -57,7 +57,7 @@ describe("AgencyGenerator - Function Parameter Type Hints", () => {
|
|
|
57
57
|
];
|
|
58
58
|
testCases.forEach(({ description, input, expectedOutput }) => {
|
|
59
59
|
it(`should correctly generate ${description}`, () => {
|
|
60
|
-
const parseResult = parseAgency(input);
|
|
60
|
+
const parseResult = parseAgency(input, {}, false);
|
|
61
61
|
expect(parseResult.success).toBe(true);
|
|
62
62
|
if (!parseResult.success)
|
|
63
63
|
return;
|
|
@@ -73,7 +73,7 @@ describe("AgencyGenerator - Function Parameter Type Hints", () => {
|
|
|
73
73
|
describe("Type preservation", () => {
|
|
74
74
|
it("should preserve primitive types", () => {
|
|
75
75
|
const input = "def test(n: number, s: string, b: boolean) { n }";
|
|
76
|
-
const parseResult = parseAgency(input);
|
|
76
|
+
const parseResult = parseAgency(input, {}, false);
|
|
77
77
|
expect(parseResult.success).toBe(true);
|
|
78
78
|
if (!parseResult.success)
|
|
79
79
|
return;
|
|
@@ -85,7 +85,7 @@ describe("AgencyGenerator - Function Parameter Type Hints", () => {
|
|
|
85
85
|
});
|
|
86
86
|
it("should preserve array types", () => {
|
|
87
87
|
const input = "def test(nums: number[], strs: string[]) { nums }";
|
|
88
|
-
const parseResult = parseAgency(input);
|
|
88
|
+
const parseResult = parseAgency(input, {}, false);
|
|
89
89
|
expect(parseResult.success).toBe(true);
|
|
90
90
|
if (!parseResult.success)
|
|
91
91
|
return;
|
|
@@ -96,7 +96,7 @@ describe("AgencyGenerator - Function Parameter Type Hints", () => {
|
|
|
96
96
|
});
|
|
97
97
|
it("should preserve union types", () => {
|
|
98
98
|
const input = "def test(val: string | number | boolean) { val }";
|
|
99
|
-
const parseResult = parseAgency(input);
|
|
99
|
+
const parseResult = parseAgency(input, {}, false);
|
|
100
100
|
expect(parseResult.success).toBe(true);
|
|
101
101
|
if (!parseResult.success)
|
|
102
102
|
return;
|
|
@@ -106,7 +106,7 @@ describe("AgencyGenerator - Function Parameter Type Hints", () => {
|
|
|
106
106
|
});
|
|
107
107
|
it("should preserve nested array types", () => {
|
|
108
108
|
const input = "def test(matrix: number[][]) { matrix }";
|
|
109
|
-
const parseResult = parseAgency(input);
|
|
109
|
+
const parseResult = parseAgency(input, {}, false);
|
|
110
110
|
expect(parseResult.success).toBe(true);
|
|
111
111
|
if (!parseResult.success)
|
|
112
112
|
return;
|
|
@@ -118,7 +118,7 @@ describe("AgencyGenerator - Function Parameter Type Hints", () => {
|
|
|
118
118
|
describe("Mixed typed and untyped parameters", () => {
|
|
119
119
|
it("should handle first parameter typed, second untyped", () => {
|
|
120
120
|
const input = "def test(x: number, y) { x }";
|
|
121
|
-
const parseResult = parseAgency(input);
|
|
121
|
+
const parseResult = parseAgency(input, {}, false);
|
|
122
122
|
expect(parseResult.success).toBe(true);
|
|
123
123
|
if (!parseResult.success)
|
|
124
124
|
return;
|
|
@@ -130,7 +130,7 @@ describe("AgencyGenerator - Function Parameter Type Hints", () => {
|
|
|
130
130
|
});
|
|
131
131
|
it("should handle first parameter untyped, second typed", () => {
|
|
132
132
|
const input = "def test(x, y: string) { x }";
|
|
133
|
-
const parseResult = parseAgency(input);
|
|
133
|
+
const parseResult = parseAgency(input, {}, false);
|
|
134
134
|
expect(parseResult.success).toBe(true);
|
|
135
135
|
if (!parseResult.success)
|
|
136
136
|
return;
|
|
@@ -142,7 +142,7 @@ describe("AgencyGenerator - Function Parameter Type Hints", () => {
|
|
|
142
142
|
});
|
|
143
143
|
it("should handle alternating typed and untyped parameters", () => {
|
|
144
144
|
const input = "def test(a, b: number, c, d: string) { a }";
|
|
145
|
-
const parseResult = parseAgency(input);
|
|
145
|
+
const parseResult = parseAgency(input, {}, false);
|
|
146
146
|
expect(parseResult.success).toBe(true);
|
|
147
147
|
if (!parseResult.success)
|
|
148
148
|
return;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { SourceLocation } from "../types/base.js";
|
|
2
|
+
export type SourceMapLocation = {
|
|
3
|
+
line: number;
|
|
4
|
+
col: number;
|
|
5
|
+
};
|
|
6
|
+
export type SourceMap = Record<string, Record<string, SourceMapLocation>>;
|
|
7
|
+
export declare class SourceMapBuilder {
|
|
8
|
+
private currentKey;
|
|
9
|
+
private map;
|
|
10
|
+
enterScope(moduleId: string, scopeName: string): void;
|
|
11
|
+
record(subStepPath: number[], loc: SourceLocation | undefined): void;
|
|
12
|
+
build(): SourceMap;
|
|
13
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export class SourceMapBuilder {
|
|
2
|
+
currentKey = "";
|
|
3
|
+
map = {};
|
|
4
|
+
enterScope(moduleId, scopeName) {
|
|
5
|
+
this.currentKey = `${moduleId}:${scopeName}`;
|
|
6
|
+
if (!this.map[this.currentKey]) {
|
|
7
|
+
this.map[this.currentKey] = {};
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
record(subStepPath, loc) {
|
|
11
|
+
if (!loc || !this.currentKey)
|
|
12
|
+
return;
|
|
13
|
+
this.map[this.currentKey][subStepPath.join(".")] = { line: loc.line, col: loc.col };
|
|
14
|
+
}
|
|
15
|
+
build() {
|
|
16
|
+
return structuredClone(this.map);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { describe, it, expect } from "vitest";
|
|
2
|
+
import { SourceMapBuilder } from "./sourceMap.js";
|
|
3
|
+
describe("SourceMapBuilder", () => {
|
|
4
|
+
it("records entries and builds correct structure", () => {
|
|
5
|
+
const builder = new SourceMapBuilder();
|
|
6
|
+
builder.enterScope("foo.agency", "main");
|
|
7
|
+
builder.record([0], { line: 1, col: 2, start: 0, end: 10 });
|
|
8
|
+
builder.record([1], { line: 3, col: 2, start: 20, end: 30 });
|
|
9
|
+
const result = builder.build();
|
|
10
|
+
expect(result).toEqual({
|
|
11
|
+
"foo.agency:main": {
|
|
12
|
+
"0": { line: 1, col: 2 },
|
|
13
|
+
"1": { line: 3, col: 2 },
|
|
14
|
+
},
|
|
15
|
+
});
|
|
16
|
+
});
|
|
17
|
+
it("handles multiple scopes", () => {
|
|
18
|
+
const builder = new SourceMapBuilder();
|
|
19
|
+
builder.enterScope("foo.agency", "main");
|
|
20
|
+
builder.record([0], { line: 1, col: 2, start: 0, end: 10 });
|
|
21
|
+
builder.enterScope("foo.agency", "greet");
|
|
22
|
+
builder.record([0], { line: 5, col: 2, start: 50, end: 60 });
|
|
23
|
+
const result = builder.build();
|
|
24
|
+
expect(result).toHaveProperty("foo.agency:main");
|
|
25
|
+
expect(result).toHaveProperty("foo.agency:greet");
|
|
26
|
+
});
|
|
27
|
+
it("silently skips undefined loc", () => {
|
|
28
|
+
const builder = new SourceMapBuilder();
|
|
29
|
+
builder.enterScope("foo.agency", "main");
|
|
30
|
+
builder.record([0], undefined);
|
|
31
|
+
builder.record([1], { line: 3, col: 2, start: 20, end: 30 });
|
|
32
|
+
const result = builder.build();
|
|
33
|
+
expect(result["foo.agency:main"]).toEqual({
|
|
34
|
+
"1": { line: 3, col: 2 },
|
|
35
|
+
});
|
|
36
|
+
});
|
|
37
|
+
it("formats substep paths with dot separator", () => {
|
|
38
|
+
const builder = new SourceMapBuilder();
|
|
39
|
+
builder.enterScope("foo.agency", "main");
|
|
40
|
+
builder.record([2, 0, 1], { line: 10, col: 4, start: 100, end: 120 });
|
|
41
|
+
const result = builder.build();
|
|
42
|
+
expect(result["foo.agency:main"]).toHaveProperty("2.0.1");
|
|
43
|
+
});
|
|
44
|
+
it("returns empty object when nothing recorded", () => {
|
|
45
|
+
const builder = new SourceMapBuilder();
|
|
46
|
+
expect(builder.build()).toEqual({});
|
|
47
|
+
});
|
|
48
|
+
it("build returns a copy, not the internal reference", () => {
|
|
49
|
+
const builder = new SourceMapBuilder();
|
|
50
|
+
builder.enterScope("foo.agency", "main");
|
|
51
|
+
builder.record([0], { line: 1, col: 2, start: 0, end: 10 });
|
|
52
|
+
const result1 = builder.build();
|
|
53
|
+
result1["foo.agency:main"]["0"].line = 999;
|
|
54
|
+
const result2 = builder.build();
|
|
55
|
+
expect(result2["foo.agency:main"]["0"].line).toBe(1);
|
|
56
|
+
});
|
|
57
|
+
});
|
|
@@ -15,12 +15,17 @@ export declare class TypeScriptBuilder {
|
|
|
15
15
|
private loopVars;
|
|
16
16
|
private insideMessageThread;
|
|
17
17
|
private insideHandlerBody;
|
|
18
|
+
private _blockCounter;
|
|
19
|
+
/** Stack of loop subKeys for generating break/continue cleanup code.
|
|
20
|
+
* Pushed when entering a stepped loop, popped when leaving. */
|
|
21
|
+
private _loopContextStack;
|
|
18
22
|
private _asyncBranchCheckNeeded;
|
|
19
23
|
/** Tracks the current substep nesting path. Empty when at the top level
|
|
20
24
|
* of a stepped body. Non-empty when inside a block (if/else, etc.) that
|
|
21
25
|
* has been broken into substeps. Used to generate unique variable names
|
|
22
26
|
* like __substep_3_1 for nested blocks. */
|
|
23
27
|
private _subStepPath;
|
|
28
|
+
private _sourceMapBuilder;
|
|
24
29
|
private programInfo;
|
|
25
30
|
private moduleId;
|
|
26
31
|
/**
|
|
@@ -44,9 +49,11 @@ export declare class TypeScriptBuilder {
|
|
|
44
49
|
*/
|
|
45
50
|
private scopedAssign;
|
|
46
51
|
private currentScopeKey;
|
|
47
|
-
|
|
52
|
+
/** Returns the name of the current scope (function, node, or block name, or empty string for global). */
|
|
53
|
+
private currentScopeName;
|
|
54
|
+
/** Returns the template opts for checkpoint creation (moduleId, scopeName, stepPath as JSON-quoted strings). */
|
|
55
|
+
private checkpointOpts;
|
|
48
56
|
private getVisibleTypeAliases;
|
|
49
|
-
private getVisibleTypeHints;
|
|
50
57
|
private forkBranchSetup;
|
|
51
58
|
private isImportedTool;
|
|
52
59
|
private static RUNTIME_STATEFUL_FUNCTIONS;
|
|
@@ -59,9 +66,19 @@ export declare class TypeScriptBuilder {
|
|
|
59
66
|
private needsParensLeft;
|
|
60
67
|
private needsParensRight;
|
|
61
68
|
build(program: AgencyProgram): TsNode;
|
|
69
|
+
/** Named args are cosmetic/positional — validate name matches the param at that index. */
|
|
70
|
+
private validateNamedArgs;
|
|
71
|
+
/** Process a function call argument, unwrapping NamedArgument and SplatExpression. */
|
|
72
|
+
private processCallArg;
|
|
73
|
+
/**
|
|
74
|
+
* Adjust call-site arguments to match the function's parameter list:
|
|
75
|
+
* 1. Pad omitted optional args (those with defaults) with null
|
|
76
|
+
* 2. Wrap extra args into an array for variadic params
|
|
77
|
+
*/
|
|
78
|
+
private adjustCallArgs;
|
|
62
79
|
private processNode;
|
|
80
|
+
private processKeyword;
|
|
63
81
|
private processTypeAlias;
|
|
64
|
-
private processTypeHint;
|
|
65
82
|
private processComment;
|
|
66
83
|
private processAgencyObject;
|
|
67
84
|
private processAgencyArray;
|
|
@@ -86,6 +103,7 @@ export declare class TypeScriptBuilder {
|
|
|
86
103
|
private generateToolRegistry;
|
|
87
104
|
private processFunctionDefinition;
|
|
88
105
|
private processStatement;
|
|
106
|
+
private buildInterruptReturn;
|
|
89
107
|
private processFunctionCallAsStatement;
|
|
90
108
|
private processFunctionCall;
|
|
91
109
|
private generateFunctionCallExpression;
|
|
@@ -101,11 +119,16 @@ export declare class TypeScriptBuilder {
|
|
|
101
119
|
* response format from type hints, and tools from config object.
|
|
102
120
|
*/
|
|
103
121
|
private processLlmCall;
|
|
104
|
-
private
|
|
122
|
+
private processSentinel;
|
|
123
|
+
private processDebuggerStatement;
|
|
105
124
|
private processSpecialVar;
|
|
106
125
|
private processMessageThread;
|
|
107
126
|
private processBlockPlain;
|
|
108
127
|
private processHandleBlockWithSteps;
|
|
128
|
+
/** In debugger mode, insert debuggerStatement nodes before each
|
|
129
|
+
* step-triggering statement so that debugStep() is called at every
|
|
130
|
+
* substep boundary, not just top-level steps. */
|
|
131
|
+
private insertDebugSteps;
|
|
109
132
|
private processBodyAsParts;
|
|
110
133
|
private generateBuiltins;
|
|
111
134
|
private generateImports;
|