greybel-interpreter 4.6.2 → 4.6.4

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.
@@ -1,12 +1,16 @@
1
+ import { ASTBase } from 'miniscript-core';
1
2
  import { HandlerContainer } from '../handler-container';
2
3
  import { Stack } from '../utils/stack';
3
- import { Instruction } from './instruction';
4
+ import { Instruction, SourceLocation } from './instruction';
4
5
  import { Module } from './module';
5
6
  export interface ContextOptions {
6
7
  target: string;
7
8
  handler: HandlerContainer;
8
9
  debugMode?: boolean;
9
10
  }
11
+ export type ContextInstruction = Partial<Instruction> & Required<Pick<Instruction, 'op'>> & {
12
+ goto?: ContextInstruction;
13
+ };
10
14
  export declare class Context {
11
15
  protected _target: Stack<string>;
12
16
  protected _handler: HandlerContainer;
@@ -19,4 +23,8 @@ export declare class Context {
19
23
  get handler(): HandlerContainer;
20
24
  get imports(): Map<string, Instruction[]>;
21
25
  isDebugMode(): boolean;
26
+ pushCode(intstruction: ContextInstruction, node: ASTBase, name?: string): void;
27
+ pushInternalCode(intstruction: ContextInstruction): void;
28
+ getSourceLocation(node: ASTBase, name?: string): SourceLocation;
29
+ getInternalLocation(): SourceLocation;
22
30
  }
@@ -27,5 +27,30 @@ class Context {
27
27
  isDebugMode() {
28
28
  return this._debugMode;
29
29
  }
30
+ pushCode(intstruction, node, name) {
31
+ intstruction.source = this.getSourceLocation(node, name);
32
+ this.module.peek().pushCode(intstruction);
33
+ }
34
+ pushInternalCode(intstruction) {
35
+ intstruction.source = this.getInternalLocation();
36
+ this.module.peek().pushCode(intstruction);
37
+ }
38
+ getSourceLocation(node, name) {
39
+ const target = this.target.peek();
40
+ return {
41
+ name: name !== null && name !== void 0 ? name : node.type,
42
+ path: target,
43
+ start: node.start,
44
+ end: node.end
45
+ };
46
+ }
47
+ getInternalLocation() {
48
+ return {
49
+ name: 'internal',
50
+ path: 'internal',
51
+ start: { line: 0, character: 0 },
52
+ end: { line: 0, character: 0 }
53
+ };
54
+ }
30
55
  }
31
56
  exports.Context = Context;