greybel-interpreter 4.0.2 → 4.0.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.
@@ -743,6 +743,15 @@ class BytecodeGenerator {
743
743
  for (const item of node.body) {
744
744
  yield this.processNode(item);
745
745
  }
746
+ this.push({
747
+ op: instruction_1.OpCode.PUSH,
748
+ source: this.getInternalLocation(),
749
+ value: default_1.DefaultType.Void
750
+ });
751
+ this.push({
752
+ op: instruction_1.OpCode.RETURN,
753
+ source: this.getInternalLocation()
754
+ });
746
755
  const fnCode = this.popContext().code;
747
756
  this.push({
748
757
  op: instruction_1.OpCode.FUNCTION_DEFINITION,
@@ -1,4 +1,4 @@
1
- import { OperationContext } from '../context';
1
+ import type { VM } from '../vm';
2
2
  export interface KeyEvent {
3
3
  keyCode?: number;
4
4
  charCode?: number;
@@ -9,16 +9,16 @@ export interface PrintOptions {
9
9
  replace: boolean;
10
10
  }
11
11
  export declare abstract class OutputHandler {
12
- abstract print(ctx: OperationContext, message: string, options?: Partial<PrintOptions>): void;
13
- abstract progress(ctx: OperationContext, timeout: number): PromiseLike<void>;
14
- abstract waitForInput(ctx: OperationContext, isPassword: boolean, message?: string): PromiseLike<string>;
15
- abstract waitForKeyPress(ctx: OperationContext, message?: string): PromiseLike<KeyEvent>;
16
- abstract clear(ctx: OperationContext): void;
12
+ abstract print(vm: VM, message: string, options?: Partial<PrintOptions>): void;
13
+ abstract progress(vm: VM, timeout: number): PromiseLike<void>;
14
+ abstract waitForInput(vm: VM, isPassword: boolean, message?: string): PromiseLike<string>;
15
+ abstract waitForKeyPress(vm: VM, message?: string): PromiseLike<KeyEvent>;
16
+ abstract clear(vm: VM): void;
17
17
  }
18
18
  export declare class DefaultOutputHandler extends OutputHandler {
19
- print(_ctx: OperationContext, message: string, { appendNewLine }?: Partial<PrintOptions>): void;
20
- progress(_ctx: OperationContext, timeout: number): PromiseLike<void>;
21
- waitForInput(_ctx: OperationContext, _isPassword: boolean, _message?: string): PromiseLike<string>;
22
- waitForKeyPress(_ctx: OperationContext, _message?: string): PromiseLike<KeyEvent>;
23
- clear(_ctx: OperationContext): void;
19
+ print(_vm: VM, message: string, { appendNewLine }?: Partial<PrintOptions>): void;
20
+ progress(_vm: VM, timeout: number): PromiseLike<void>;
21
+ waitForInput(_vm: VM, _isPassword: boolean, _message?: string): PromiseLike<string>;
22
+ waitForKeyPress(_vm: VM, _message?: string): PromiseLike<KeyEvent>;
23
+ clear(_vm: VM): void;
24
24
  }
@@ -5,7 +5,7 @@ class OutputHandler {
5
5
  }
6
6
  exports.OutputHandler = OutputHandler;
7
7
  class DefaultOutputHandler extends OutputHandler {
8
- print(_ctx, message, { appendNewLine = true } = {}) {
8
+ print(_vm, message, { appendNewLine = true } = {}) {
9
9
  if (appendNewLine) {
10
10
  process.stdout.write(message + '\n');
11
11
  }
@@ -13,21 +13,21 @@ class DefaultOutputHandler extends OutputHandler {
13
13
  process.stdout.write(message);
14
14
  }
15
15
  }
16
- progress(_ctx, timeout) {
16
+ progress(_vm, timeout) {
17
17
  return new Promise((resolve, _reject) => {
18
18
  setTimeout(resolve, timeout);
19
19
  });
20
20
  }
21
- waitForInput(_ctx, _isPassword, _message) {
21
+ waitForInput(_vm, _isPassword, _message) {
22
22
  return Promise.resolve('test');
23
23
  }
24
- waitForKeyPress(_ctx, _message) {
24
+ waitForKeyPress(_vm, _message) {
25
25
  return Promise.resolve({
26
26
  keyCode: 13,
27
27
  code: 'Enter'
28
28
  });
29
29
  }
30
- clear(_ctx) {
30
+ clear(_vm) {
31
31
  console.clear();
32
32
  }
33
33
  }
package/dist/vm.js CHANGED
@@ -625,7 +625,7 @@ class VM {
625
625
  case instruction_1.OpCode.RETURN: {
626
626
  const value = this.popStack();
627
627
  this.popFrame();
628
- this.pushStack(value);
628
+ this.pushStack(value !== null && value !== void 0 ? value : default_1.DefaultType.Void);
629
629
  break;
630
630
  }
631
631
  case instruction_1.OpCode.GET_ENVAR: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "greybel-interpreter",
3
- "version": "4.0.2",
3
+ "version": "4.0.4",
4
4
  "description": "Interpreter",
5
5
  "main": "dist/index",
6
6
  "typings": "dist/index",