@vnejs/plugins.core.stack 0.0.1
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/const/events.js +7 -0
- package/index.js +9 -0
- package/modules/call.js +27 -0
- package/modules/jmp.js +25 -0
- package/modules/stack.js +41 -0
- package/package.json +18 -0
package/const/events.js
ADDED
package/index.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { regPlugin } from "@vnejs/shared";
|
|
2
|
+
|
|
3
|
+
import { SUBSCRIBE_EVENTS } from "./const/events";
|
|
4
|
+
|
|
5
|
+
import { Stack } from "./modules/stack";
|
|
6
|
+
import { Call } from "./modules/call";
|
|
7
|
+
import { Jmp } from "./modules/jmp";
|
|
8
|
+
|
|
9
|
+
regPlugin("STACK", { events: SUBSCRIBE_EVENTS }, [Stack, Call, Jmp]);
|
package/modules/call.js
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { Module } from "@vnejs/module";
|
|
2
|
+
|
|
3
|
+
export class Call extends Module {
|
|
4
|
+
name = "call";
|
|
5
|
+
subscribe = () => {
|
|
6
|
+
this.on(this.EVENTS.STACK.CALL, this.onStackCall);
|
|
7
|
+
};
|
|
8
|
+
init = async () => {
|
|
9
|
+
await this.emit(this.EVENTS.SCENARIO.EXEC_REG, { module: this.name, handler: this.execHandler });
|
|
10
|
+
await this.emit(this.EVENTS.SCENARIO.LINE_REG, { module: this.name, handler: this.preloadHandler });
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
execHandler = async (label) => {
|
|
14
|
+
await this.emit(this.EVENTS.STACK.CALL, { label });
|
|
15
|
+
this.emitNext();
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
preloadHandler = async ({ line: label, isConstant = false, deep } = {}) => ({ label, deep: deep - 1, isConstant });
|
|
19
|
+
|
|
20
|
+
onStackCall = async ({ label } = {}) => {
|
|
21
|
+
this.log({ label });
|
|
22
|
+
|
|
23
|
+
this.globalState.stack.stack.push(this.globalState.scenario);
|
|
24
|
+
|
|
25
|
+
await this.emit(this.EVENTS.STACK.EMIT, { label });
|
|
26
|
+
};
|
|
27
|
+
}
|
package/modules/jmp.js
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { Module } from "@vnejs/module";
|
|
2
|
+
|
|
3
|
+
export class Jmp extends Module {
|
|
4
|
+
name = "jmp";
|
|
5
|
+
subscribe = () => {
|
|
6
|
+
this.on(this.EVENTS.STACK.JMP, this.onStackJmp);
|
|
7
|
+
};
|
|
8
|
+
init = async () => {
|
|
9
|
+
await this.emit(this.EVENTS.SCENARIO.EXEC_REG, { module: this.name, handler: this.execHandler });
|
|
10
|
+
await this.emit(this.EVENTS.SCENARIO.LINE_REG, { module: this.name, handler: this.preloadHandler });
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
execHandler = async (label) => {
|
|
14
|
+
await this.emit(this.EVENTS.STACK.JMP, { label });
|
|
15
|
+
this.emitNext();
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
preloadHandler = async ({ line: label, isConstant = false, deep } = {}) => ({ label, deep: deep - 1, isConstant });
|
|
19
|
+
|
|
20
|
+
onStackJmp = async ({ label } = {}) => {
|
|
21
|
+
this.log({ label });
|
|
22
|
+
|
|
23
|
+
await this.emit(this.EVENTS.STACK.EMIT, { label });
|
|
24
|
+
};
|
|
25
|
+
}
|
package/modules/stack.js
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { Module } from "@vnejs/module";
|
|
2
|
+
|
|
3
|
+
export class Stack extends Module {
|
|
4
|
+
name = "stack";
|
|
5
|
+
subscribe = () => {
|
|
6
|
+
this.on(this.EVENTS.STACK.POP, this.onStackPop);
|
|
7
|
+
this.on(this.EVENTS.STACK.EMIT, this.onStackEmit);
|
|
8
|
+
this.on(this.EVENTS.STACK.CLEAR, this.onStackClear);
|
|
9
|
+
|
|
10
|
+
this.on(this.EVENTS.STATE.SET, this.setStateFromGlobalState);
|
|
11
|
+
this.on(this.EVENTS.STATE.CLEAR, this.setDefaultState);
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
init = () => this.emit(this.EVENTS.SCENARIO.EXEC_REG, { module: this.name, handler: this.execHandler });
|
|
15
|
+
|
|
16
|
+
execHandler = (action) => action === "pop" && this.emit(this.EVENTS.STACK.POP);
|
|
17
|
+
|
|
18
|
+
onStackPop = async () => {
|
|
19
|
+
if (this.state.stack.length) {
|
|
20
|
+
const { label, curLine } = this.state.stack.pop();
|
|
21
|
+
this.setScenarioState(label, curLine);
|
|
22
|
+
await this.emitNext();
|
|
23
|
+
} else await this.emit(this.EVENTS.STACK.CLEAR);
|
|
24
|
+
};
|
|
25
|
+
onStackEmit = async ({ label } = {}) => {
|
|
26
|
+
this.setScenarioState(label, 0);
|
|
27
|
+
|
|
28
|
+
this.emit(this.EVENTS.SCENARIO.LABEL_GET, { label });
|
|
29
|
+
};
|
|
30
|
+
onStackClear = async () => {
|
|
31
|
+
await this.emit(this.EVENTS.STATE.CLEAR);
|
|
32
|
+
this.emitNext();
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
setScenarioState = (label, curLine) => {
|
|
36
|
+
this.globalState.scenario.label = label;
|
|
37
|
+
this.globalState.scenario.curLine = curLine;
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
getDefaultState = () => ({ stack: [] });
|
|
41
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@vnejs/plugins.core.stack",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"main": "index.js",
|
|
5
|
+
"scripts": {
|
|
6
|
+
"test": "echo \"Error: no test specified\" && exit 1",
|
|
7
|
+
"publish:major": "npm version major && npm publish --access public",
|
|
8
|
+
"publish:minor": "npm version minor && npm publish --access public",
|
|
9
|
+
"publish:patch": "npm version patch && npm publish --access public"
|
|
10
|
+
},
|
|
11
|
+
"author": "",
|
|
12
|
+
"license": "ISC",
|
|
13
|
+
"description": "",
|
|
14
|
+
"peerDependencies": {
|
|
15
|
+
"@vnejs/shared": "*",
|
|
16
|
+
"@vnejs/module": "*"
|
|
17
|
+
}
|
|
18
|
+
}
|