greybel-interpreter 4.5.13 → 4.6.0

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.
Files changed (42) hide show
  1. package/dist/bytecode-generator/context.d.ts +22 -0
  2. package/dist/bytecode-generator/context.js +31 -0
  3. package/dist/bytecode-generator/expression.d.ts +24 -0
  4. package/dist/bytecode-generator/expression.js +640 -0
  5. package/dist/{byte-compiler → bytecode-generator}/instruction.d.ts +17 -19
  6. package/dist/{byte-compiler → bytecode-generator}/instruction.js +13 -12
  7. package/dist/bytecode-generator/line.d.ts +9 -0
  8. package/dist/bytecode-generator/line.js +2 -0
  9. package/dist/bytecode-generator/models.d.ts +42 -0
  10. package/dist/bytecode-generator/models.js +2 -0
  11. package/dist/bytecode-generator/module.d.ts +25 -0
  12. package/dist/bytecode-generator/module.js +72 -0
  13. package/dist/bytecode-generator/statement.d.ts +31 -0
  14. package/dist/bytecode-generator/statement.js +825 -0
  15. package/dist/bytecode-generator/utils.d.ts +5 -0
  16. package/dist/bytecode-generator/utils.js +30 -0
  17. package/dist/bytecode-generator.d.ts +3 -57
  18. package/dist/bytecode-generator.js +31 -1219
  19. package/dist/context.d.ts +5 -2
  20. package/dist/context.js +15 -13
  21. package/dist/index.d.ts +6 -2
  22. package/dist/index.js +10 -2
  23. package/dist/types/function.d.ts +1 -1
  24. package/dist/types/function.js +2 -2
  25. package/dist/types/map.js +10 -10
  26. package/dist/types/string.js +1 -1
  27. package/dist/utils/error.d.ts +1 -1
  28. package/dist/utils/hash.js +8 -14
  29. package/dist/utils/object-value.d.ts +1 -1
  30. package/dist/utils/object-value.js +9 -9
  31. package/dist/utils/stack.d.ts +1 -0
  32. package/dist/utils/stack.js +3 -0
  33. package/dist/utils/uuid.d.ts +2 -1
  34. package/dist/utils/uuid.js +5 -33
  35. package/dist/utils/value-hash.d.ts +2 -0
  36. package/dist/utils/value-hash.js +15 -0
  37. package/dist/vm/call.js +1 -1
  38. package/dist/vm.d.ts +1 -1
  39. package/dist/vm.js +36 -18
  40. package/package.json +4 -4
  41. /package/dist/{byte-compiler → bytecode-generator}/keywords.d.ts +0 -0
  42. /package/dist/{byte-compiler → bytecode-generator}/keywords.js +0 -0
@@ -0,0 +1,5 @@
1
+ import { ASTBase, ASTLiteral } from 'miniscript-core';
2
+ import { CustomNumber } from '../types/number';
3
+ import { CustomString } from '../types/string';
4
+ export declare function generateCustomValueFromASTLiteral(node: ASTLiteral): import("..").CustomNil | CustomNumber | CustomString;
5
+ export declare function unwrap(node: ASTBase): ASTBase;
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.unwrap = exports.generateCustomValueFromASTLiteral = void 0;
4
+ const miniscript_core_1 = require("miniscript-core");
5
+ const boolean_1 = require("../types/boolean");
6
+ const default_1 = require("../types/default");
7
+ const number_1 = require("../types/number");
8
+ const string_1 = require("../types/string");
9
+ function generateCustomValueFromASTLiteral(node) {
10
+ switch (node.type) {
11
+ case miniscript_core_1.ASTType.BooleanLiteral:
12
+ return new boolean_1.CustomBoolean(node.value);
13
+ case miniscript_core_1.ASTType.StringLiteral:
14
+ return new string_1.CustomString(node.value);
15
+ case miniscript_core_1.ASTType.NumericLiteral:
16
+ return new number_1.CustomNumber(node.value);
17
+ case miniscript_core_1.ASTType.NilLiteral:
18
+ return default_1.DefaultType.Void;
19
+ default:
20
+ throw new Error('Unexpected literal type.');
21
+ }
22
+ }
23
+ exports.generateCustomValueFromASTLiteral = generateCustomValueFromASTLiteral;
24
+ function unwrap(node) {
25
+ while (node instanceof miniscript_core_1.ASTParenthesisExpression) {
26
+ node = node.expression;
27
+ }
28
+ return node;
29
+ }
30
+ exports.unwrap = unwrap;
@@ -1,26 +1,10 @@
1
- import { ASTFeatureEnvarExpression, ASTFeatureImportExpression, ASTFeatureIncludeExpression } from 'greybel-core';
2
- import { ASTAssignmentStatement, ASTBase, ASTCallExpression, ASTEvaluationExpression, ASTForGenericStatement, ASTFunctionStatement, ASTIdentifier, ASTIfStatement, ASTListConstructorExpression, ASTLiteral, ASTMapConstructorExpression, ASTReturnStatement, ASTUnaryExpression, ASTWhileStatement, ASTSliceExpression, ASTIndexExpression, ASTMemberExpression } from 'miniscript-core';
3
- import { Instruction, SourceLocation } from './byte-compiler/instruction';
4
- import { Stack } from './utils/stack';
1
+ import { Instruction } from './bytecode-generator/instruction';
5
2
  import { HandlerContainer } from './handler-container';
6
- export interface LineContext {
7
- isCommand?: boolean;
8
- includeOuter?: boolean;
9
- }
10
- export interface LineCallableContext extends LineContext {
11
- isReference?: boolean;
12
- }
13
- export interface LineIdentifierContext extends LineCallableContext {
14
- isDescending?: boolean;
15
- }
3
+ import { Context } from './bytecode-generator/context';
16
4
  export interface BytecodeCompileResult {
17
5
  code: Instruction[];
18
6
  imports: Map<string, Instruction[]>;
19
7
  }
20
- export interface BytecodeGeneratorContext {
21
- code: Instruction[];
22
- jumpPoints: [Instruction, Instruction][];
23
- }
24
8
  export interface BytecodeConverterOptions {
25
9
  target: string;
26
10
  handler: HandlerContainer;
@@ -28,45 +12,7 @@ export interface BytecodeConverterOptions {
28
12
  }
29
13
  export declare class BytecodeGenerator {
30
14
  protected handler: HandlerContainer;
31
- protected context: Stack<BytecodeGeneratorContext>;
32
- protected target: Stack<string>;
33
- protected debugMode: boolean;
34
- protected imports: Map<string, Instruction[]>;
15
+ protected context: Context;
35
16
  constructor(options: BytecodeConverterOptions);
36
- parse(code: string): ASTBase | import("greybel-core").ASTChunkAdvanced;
37
17
  compile(code: string): Promise<BytecodeCompileResult>;
38
- protected getCurrentPointer(): number;
39
- protected getSourceLocation(node: ASTBase, name?: string): SourceLocation;
40
- protected getInternalLocation(): SourceLocation;
41
- protected pushContext(): void;
42
- protected popContext(): BytecodeGeneratorContext;
43
- protected getLastJumpPoint(): [Instruction, Instruction];
44
- protected pushJumppoint(start: Instruction, end: Instruction): void;
45
- protected popJumppoint(): [Instruction, Instruction];
46
- protected push(item: Instruction): void;
47
- protected processNode(node: ASTBase): Promise<void>;
48
- protected processSubNode(node: ASTBase, context?: LineContext): Promise<void>;
49
- protected processMemberExpression(node: ASTMemberExpression, context?: LineCallableContext): Promise<void>;
50
- protected processIndexExpression(node: ASTIndexExpression, context?: LineCallableContext): Promise<void>;
51
- protected processSliceExpression(node: ASTSliceExpression): Promise<void>;
52
- protected processIdentifier(node: ASTIdentifier, context?: LineIdentifierContext): Promise<void>;
53
- protected processAssignmentStatement(node: ASTAssignmentStatement): Promise<void>;
54
- protected processLiteral(node: ASTLiteral): Promise<void>;
55
- protected processEvaluationExpression(node: ASTEvaluationExpression): Promise<void>;
56
- protected processReturn(node: ASTReturnStatement): Promise<void>;
57
- protected processBreak(node: ASTBase): Promise<void>;
58
- protected processContinue(node: ASTBase): Promise<void>;
59
- protected processMapConstructorExpression(node: ASTMapConstructorExpression): Promise<void>;
60
- protected processListConstructorExpression(node: ASTListConstructorExpression): Promise<void>;
61
- protected processFunctionDeclaration(node: ASTFunctionStatement, context?: LineContext): Promise<void>;
62
- protected processWhileStatement(node: ASTWhileStatement): Promise<void>;
63
- protected processUnaryExpression(node: ASTUnaryExpression): Promise<void>;
64
- protected processCallExpression(node: ASTCallExpression): Promise<void>;
65
- protected processIfStatement(node: ASTIfStatement): Promise<void>;
66
- protected processForGenericStatement(node: ASTForGenericStatement): Promise<void>;
67
- protected processEnvarExpression(node: ASTFeatureEnvarExpression): Promise<void>;
68
- protected createImport(node: ASTFeatureImportExpression, path: string, code: string): Promise<void>;
69
- protected processImportExpression(node: ASTFeatureImportExpression): Promise<void>;
70
- protected processIncludeExpression(node: ASTFeatureIncludeExpression): Promise<void>;
71
- protected processDebuggerExpression(node: ASTBase): Promise<void>;
72
18
  }