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
@@ -47,18 +47,19 @@ export declare enum OpCode {
47
47
  GOTO_A = 41,
48
48
  GOTO_A_IF_FALSE = 42,
49
49
  GOTO_A_IF_FALSE_AND_PUSH = 43,
50
- GOTO_A_IF_TRUE_AND_PUSH = 44,
51
- PUSH_ITERATOR = 45,
52
- POP_ITERATOR = 46,
53
- NEXT = 47,
54
- BITWISE_OR = 48,
55
- BITWISE_AND = 49,
56
- BITWISE_LEFT_SHIFT = 50,
57
- BITWISE_RIGHT_SHIFT = 51,
58
- BITWISE_UNSIGNED_RIGHT_SHIFT = 52,
59
- BREAKPOINT = 53,
60
- BREAKPOINT_ENABLE = 54,
61
- IMPORT = 55
50
+ GOTO_A_IF_TRUE = 44,
51
+ GOTO_A_IF_TRUE_AND_PUSH = 45,
52
+ PUSH_ITERATOR = 46,
53
+ POP_ITERATOR = 47,
54
+ NEXT = 48,
55
+ BITWISE_OR = 49,
56
+ BITWISE_AND = 50,
57
+ BITWISE_LEFT_SHIFT = 51,
58
+ BITWISE_RIGHT_SHIFT = 52,
59
+ BITWISE_UNSIGNED_RIGHT_SHIFT = 53,
60
+ BREAKPOINT = 54,
61
+ BREAKPOINT_ENABLE = 55,
62
+ IMPORT = 56
62
63
  }
63
64
  export interface FunctionDefinitionInstructionArgument {
64
65
  name: CustomString;
@@ -74,6 +75,7 @@ export interface BaseInstruction {
74
75
  op: OpCode;
75
76
  source: SourceLocation;
76
77
  ip?: number;
78
+ command?: boolean;
77
79
  }
78
80
  export interface GetVariableInstruction extends BaseInstruction {
79
81
  op: OpCode.GET_VARIABLE;
@@ -97,11 +99,7 @@ export interface ConstructListInstruction extends BaseInstruction {
97
99
  length: number;
98
100
  }
99
101
  export interface CallInstruction extends BaseInstruction {
100
- op: OpCode.CALL;
101
- length: number;
102
- }
103
- export interface CallWithContextInstruction extends BaseInstruction {
104
- op: OpCode.CALL_WITH_CONTEXT | OpCode.CALL_SUPER_PROPERTY;
102
+ op: OpCode.CALL | OpCode.CALL_WITH_CONTEXT | OpCode.CALL_SUPER_PROPERTY;
105
103
  length: number;
106
104
  }
107
105
  export interface FunctionDefinitionInstruction extends BaseInstruction {
@@ -111,7 +109,7 @@ export interface FunctionDefinitionInstruction extends BaseInstruction {
111
109
  ignoreOuter: boolean;
112
110
  }
113
111
  export interface GotoAInstruction extends BaseInstruction {
114
- op: OpCode.GOTO_A | OpCode.GOTO_A_IF_FALSE | OpCode.GOTO_A_IF_FALSE_AND_PUSH | OpCode.GOTO_A_IF_TRUE_AND_PUSH;
112
+ op: OpCode.GOTO_A | OpCode.GOTO_A_IF_FALSE | OpCode.GOTO_A_IF_FALSE_AND_PUSH | OpCode.GOTO_A_IF_TRUE | OpCode.GOTO_A_IF_TRUE_AND_PUSH;
115
113
  goto: Instruction;
116
114
  }
117
115
  export interface NextInstruction extends BaseInstruction {
@@ -129,4 +127,4 @@ export interface ImportInstruction extends BaseInstruction {
129
127
  op: OpCode.IMPORT;
130
128
  path: string;
131
129
  }
132
- export type Instruction = BaseInstruction | GetVariableInstruction | PushInstruction | ConstructMapInstruction | ConstructListInstruction | FunctionDefinitionInstruction | GotoAInstruction | GetPropertyInstruction | CallInstruction | CallWithContextInstruction | NextInstruction | CallInternalInstruction | ImportInstruction;
130
+ export type Instruction = BaseInstruction | GetVariableInstruction | PushInstruction | ConstructMapInstruction | ConstructListInstruction | FunctionDefinitionInstruction | GotoAInstruction | GetPropertyInstruction | CallInstruction | NextInstruction | CallInternalInstruction | ImportInstruction;
@@ -47,16 +47,17 @@ var OpCode;
47
47
  OpCode[OpCode["GOTO_A"] = 41] = "GOTO_A";
48
48
  OpCode[OpCode["GOTO_A_IF_FALSE"] = 42] = "GOTO_A_IF_FALSE";
49
49
  OpCode[OpCode["GOTO_A_IF_FALSE_AND_PUSH"] = 43] = "GOTO_A_IF_FALSE_AND_PUSH";
50
- OpCode[OpCode["GOTO_A_IF_TRUE_AND_PUSH"] = 44] = "GOTO_A_IF_TRUE_AND_PUSH";
51
- OpCode[OpCode["PUSH_ITERATOR"] = 45] = "PUSH_ITERATOR";
52
- OpCode[OpCode["POP_ITERATOR"] = 46] = "POP_ITERATOR";
53
- OpCode[OpCode["NEXT"] = 47] = "NEXT";
54
- OpCode[OpCode["BITWISE_OR"] = 48] = "BITWISE_OR";
55
- OpCode[OpCode["BITWISE_AND"] = 49] = "BITWISE_AND";
56
- OpCode[OpCode["BITWISE_LEFT_SHIFT"] = 50] = "BITWISE_LEFT_SHIFT";
57
- OpCode[OpCode["BITWISE_RIGHT_SHIFT"] = 51] = "BITWISE_RIGHT_SHIFT";
58
- OpCode[OpCode["BITWISE_UNSIGNED_RIGHT_SHIFT"] = 52] = "BITWISE_UNSIGNED_RIGHT_SHIFT";
59
- OpCode[OpCode["BREAKPOINT"] = 53] = "BREAKPOINT";
60
- OpCode[OpCode["BREAKPOINT_ENABLE"] = 54] = "BREAKPOINT_ENABLE";
61
- OpCode[OpCode["IMPORT"] = 55] = "IMPORT";
50
+ OpCode[OpCode["GOTO_A_IF_TRUE"] = 44] = "GOTO_A_IF_TRUE";
51
+ OpCode[OpCode["GOTO_A_IF_TRUE_AND_PUSH"] = 45] = "GOTO_A_IF_TRUE_AND_PUSH";
52
+ OpCode[OpCode["PUSH_ITERATOR"] = 46] = "PUSH_ITERATOR";
53
+ OpCode[OpCode["POP_ITERATOR"] = 47] = "POP_ITERATOR";
54
+ OpCode[OpCode["NEXT"] = 48] = "NEXT";
55
+ OpCode[OpCode["BITWISE_OR"] = 49] = "BITWISE_OR";
56
+ OpCode[OpCode["BITWISE_AND"] = 50] = "BITWISE_AND";
57
+ OpCode[OpCode["BITWISE_LEFT_SHIFT"] = 51] = "BITWISE_LEFT_SHIFT";
58
+ OpCode[OpCode["BITWISE_RIGHT_SHIFT"] = 52] = "BITWISE_RIGHT_SHIFT";
59
+ OpCode[OpCode["BITWISE_UNSIGNED_RIGHT_SHIFT"] = 53] = "BITWISE_UNSIGNED_RIGHT_SHIFT";
60
+ OpCode[OpCode["BREAKPOINT"] = 54] = "BREAKPOINT";
61
+ OpCode[OpCode["BREAKPOINT_ENABLE"] = 55] = "BREAKPOINT_ENABLE";
62
+ OpCode[OpCode["IMPORT"] = 56] = "IMPORT";
62
63
  })(OpCode = exports.OpCode || (exports.OpCode = {}));
@@ -0,0 +1,9 @@
1
+ export interface LineContext {
2
+ includeOuter?: boolean;
3
+ }
4
+ export interface LineCallableContext extends LineContext {
5
+ isReference?: boolean;
6
+ }
7
+ export interface LineIdentifierContext extends LineCallableContext {
8
+ isDescending?: boolean;
9
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,42 @@
1
+ import { ASTFeatureEnvarExpression, ASTFeatureImportExpression, ASTFeatureIncludeExpression } from 'greybel-core';
2
+ import { ASTAssignmentStatement, ASTBase, ASTCallExpression, ASTEvaluationExpression, ASTForGenericStatement, ASTFunctionStatement, ASTIdentifier, ASTIfStatement, ASTIndexExpression, ASTListConstructorExpression, ASTLiteral, ASTMapConstructorExpression, ASTMemberExpression, ASTReturnStatement, ASTSliceExpression, ASTUnaryExpression, ASTWhileStatement } from 'miniscript-core';
3
+ import { LineCallableContext, LineContext, LineIdentifierContext } from './line';
4
+ export interface ParseCodeFunction {
5
+ (code: string): ASTBase;
6
+ }
7
+ export interface IBytecodeStatementGenerator {
8
+ process(node: ASTBase): Promise<void>;
9
+ processMemberExpression(node: ASTMemberExpression, context?: LineCallableContext): Promise<void>;
10
+ processIndexExpression(node: ASTIndexExpression, context?: LineCallableContext): Promise<void>;
11
+ processIdentifier(node: ASTIdentifier, context?: LineIdentifierContext): Promise<void>;
12
+ processAssignmentStatement(node: ASTAssignmentStatement): Promise<void>;
13
+ processEvaluationExpression(node: ASTEvaluationExpression): Promise<void>;
14
+ processReturn(node: ASTReturnStatement): Promise<void>;
15
+ processBreak(node: ASTBase): Promise<void>;
16
+ processContinue(node: ASTBase): Promise<void>;
17
+ processMapConstructorExpression(node: ASTMapConstructorExpression): Promise<void>;
18
+ processListConstructorExpression(node: ASTListConstructorExpression): Promise<void>;
19
+ processWhileStatement(node: ASTWhileStatement): Promise<void>;
20
+ processUnaryExpression(node: ASTUnaryExpression): Promise<void>;
21
+ processCallExpression(node: ASTCallExpression): Promise<void>;
22
+ processIfStatement(node: ASTIfStatement): Promise<void>;
23
+ processForGenericStatement(node: ASTForGenericStatement): Promise<void>;
24
+ processImportExpression(node: ASTFeatureImportExpression): Promise<void>;
25
+ processIncludeExpression(node: ASTFeatureIncludeExpression): Promise<void>;
26
+ processDebuggerExpression(node: ASTBase): Promise<void>;
27
+ }
28
+ export interface IBytecodeExpressionGenerator {
29
+ process(node: ASTBase, context?: LineContext): Promise<void>;
30
+ processMemberExpression(node: ASTMemberExpression, context?: LineCallableContext): Promise<void>;
31
+ processIndexExpression(node: ASTIndexExpression): Promise<void>;
32
+ processSliceExpression(node: ASTSliceExpression): Promise<void>;
33
+ processIdentifier(node: ASTIdentifier, context?: LineIdentifierContext): Promise<void>;
34
+ processLiteral(node: ASTLiteral): Promise<void>;
35
+ processEvaluationExpression(node: ASTEvaluationExpression): Promise<void>;
36
+ processMapConstructorExpression(node: ASTMapConstructorExpression): Promise<void>;
37
+ processListConstructorExpression(node: ASTListConstructorExpression): Promise<void>;
38
+ processFunctionDeclaration(node: ASTFunctionStatement, context?: LineContext): Promise<void>;
39
+ processUnaryExpression(node: ASTUnaryExpression): Promise<void>;
40
+ processCallExpression(node: ASTCallExpression): Promise<void>;
41
+ processEnvarExpression(node: ASTFeatureEnvarExpression): Promise<void>;
42
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,25 @@
1
+ import { ASTBase } from 'miniscript-core';
2
+ import { Stack } from '../utils/stack';
3
+ import { Instruction, SourceLocation } from './instruction';
4
+ export interface BytecodeGeneratorContext {
5
+ code: Instruction[];
6
+ jumpPoints: [Instruction, Instruction][];
7
+ }
8
+ export declare class Module {
9
+ private _target;
10
+ private _context;
11
+ constructor(target: string);
12
+ get target(): string;
13
+ get context(): Stack<BytecodeGeneratorContext>;
14
+ isGlobalScope(): boolean;
15
+ pushContext(): void;
16
+ popContext(): BytecodeGeneratorContext;
17
+ getCurrentIp(): number;
18
+ getCode(): Instruction[];
19
+ pushCode(item: Instruction): void;
20
+ getJumpPoint(): [Instruction, Instruction];
21
+ pushJumppoint(start: Instruction, end: Instruction): void;
22
+ popJumppoint(): [Instruction, Instruction];
23
+ getSourceLocation(node: ASTBase, name?: string): SourceLocation;
24
+ getInternalLocation(): SourceLocation;
25
+ }
@@ -0,0 +1,72 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Module = void 0;
4
+ const stack_1 = require("../utils/stack");
5
+ class Module {
6
+ constructor(target) {
7
+ this._target = target;
8
+ this._context = new stack_1.Stack({
9
+ code: [],
10
+ jumpPoints: []
11
+ });
12
+ }
13
+ get target() {
14
+ return this._target;
15
+ }
16
+ get context() {
17
+ return this._context;
18
+ }
19
+ isGlobalScope() {
20
+ return this._context.length === 1;
21
+ }
22
+ pushContext() {
23
+ this._context.push({
24
+ code: [],
25
+ jumpPoints: []
26
+ });
27
+ }
28
+ popContext() {
29
+ return this._context.pop();
30
+ }
31
+ getCurrentIp() {
32
+ return this._context.peek().code.length - 1;
33
+ }
34
+ getCode() {
35
+ return this._context.peek().code;
36
+ }
37
+ pushCode(item) {
38
+ item.ip = this.getCurrentIp() + 1;
39
+ this._context.peek().code.push(item);
40
+ }
41
+ getJumpPoint() {
42
+ const jumpPoints = this._context.peek().jumpPoints;
43
+ if (jumpPoints.length === 0) {
44
+ return null;
45
+ }
46
+ return jumpPoints[jumpPoints.length - 1];
47
+ }
48
+ pushJumppoint(start, end) {
49
+ this._context.peek().jumpPoints.push([start, end]);
50
+ }
51
+ popJumppoint() {
52
+ return this._context.peek().jumpPoints.pop();
53
+ }
54
+ getSourceLocation(node, name) {
55
+ const target = this.target;
56
+ return {
57
+ name: name !== null && name !== void 0 ? name : node.type,
58
+ path: target,
59
+ start: node.start,
60
+ end: node.end
61
+ };
62
+ }
63
+ getInternalLocation() {
64
+ return {
65
+ name: 'internal',
66
+ path: 'internal',
67
+ start: { line: 0, character: 0 },
68
+ end: { line: 0, character: 0 }
69
+ };
70
+ }
71
+ }
72
+ exports.Module = Module;
@@ -0,0 +1,31 @@
1
+ import { ASTFeatureImportExpression, ASTFeatureIncludeExpression } from 'greybel-core';
2
+ import { ASTAssignmentStatement, ASTBase, ASTCallExpression, ASTEvaluationExpression, ASTForGenericStatement, ASTIdentifier, ASTIfStatement, ASTIndexExpression, ASTListConstructorExpression, ASTMapConstructorExpression, ASTMemberExpression, ASTReturnStatement, ASTUnaryExpression, ASTWhileStatement } from 'miniscript-core';
3
+ import { Context } from './context';
4
+ import { LineCallableContext, LineIdentifierContext } from './line';
5
+ import { IBytecodeStatementGenerator, ParseCodeFunction } from './models';
6
+ export declare class BytecodeStatementGenerator implements IBytecodeStatementGenerator {
7
+ private context;
8
+ private exprGenerator;
9
+ private parseCode;
10
+ constructor(context: Context, parseCodeFunction: ParseCodeFunction);
11
+ process(node: ASTBase): Promise<void>;
12
+ processMemberExpression(node: ASTMemberExpression, context?: LineCallableContext): Promise<void>;
13
+ processIndexExpression(node: ASTIndexExpression, context?: LineCallableContext): Promise<void>;
14
+ processIdentifier(node: ASTIdentifier, context?: LineIdentifierContext): Promise<void>;
15
+ processAssignmentStatement(node: ASTAssignmentStatement): Promise<void>;
16
+ processEvaluationExpression(node: ASTEvaluationExpression): Promise<void>;
17
+ processReturn(node: ASTReturnStatement): Promise<void>;
18
+ processBreak(node: ASTBase): Promise<void>;
19
+ processContinue(node: ASTBase): Promise<void>;
20
+ processMapConstructorExpression(node: ASTMapConstructorExpression): Promise<void>;
21
+ processListConstructorExpression(node: ASTListConstructorExpression): Promise<void>;
22
+ processWhileStatement(node: ASTWhileStatement): Promise<void>;
23
+ processUnaryExpression(node: ASTUnaryExpression): Promise<void>;
24
+ processCallExpression(node: ASTCallExpression): Promise<void>;
25
+ processIfStatement(node: ASTIfStatement): Promise<void>;
26
+ processForGenericStatement(node: ASTForGenericStatement): Promise<void>;
27
+ protected createImport(node: ASTFeatureImportExpression, path: string, code: string): Promise<void>;
28
+ processImportExpression(node: ASTFeatureImportExpression): Promise<void>;
29
+ processIncludeExpression(node: ASTFeatureIncludeExpression): Promise<void>;
30
+ processDebuggerExpression(node: ASTBase): Promise<void>;
31
+ }