greyscript-interpreter 0.1.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.
- package/.editorconfig +15 -0
- package/.eslintrc +48 -0
- package/LICENSE +21 -0
- package/README.md +2 -0
- package/dist/cps.d.ts +2 -0
- package/dist/cps.js +58 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +7 -0
- package/dist/interpreter.d.ts +5 -0
- package/dist/interpreter.js +49 -0
- package/dist/operations/include.d.ts +12 -0
- package/dist/operations/include.js +39 -0
- package/package.json +58 -0
package/.editorconfig
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# EditorConfig helps developers define and maintain consistent
|
|
2
|
+
# coding styles between different editors and IDEs
|
|
3
|
+
# See http://editorconfig.org
|
|
4
|
+
root = true
|
|
5
|
+
|
|
6
|
+
[*]
|
|
7
|
+
end_of_line = lf
|
|
8
|
+
insert_final_newline = true
|
|
9
|
+
trim_trailing_whitespace = true
|
|
10
|
+
indent_style = space
|
|
11
|
+
indent_size = 2
|
|
12
|
+
charset = utf-8
|
|
13
|
+
|
|
14
|
+
[*.md]
|
|
15
|
+
trim_trailing_whitespace = false
|
package/.eslintrc
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
{
|
|
2
|
+
"parser": "@typescript-eslint/parser",
|
|
3
|
+
"plugins": [
|
|
4
|
+
"@typescript-eslint",
|
|
5
|
+
"promise",
|
|
6
|
+
"simple-import-sort",
|
|
7
|
+
"jest",
|
|
8
|
+
"security",
|
|
9
|
+
"prettier"
|
|
10
|
+
],
|
|
11
|
+
"env": {
|
|
12
|
+
"jest": true,
|
|
13
|
+
"node": true
|
|
14
|
+
},
|
|
15
|
+
"globals": {
|
|
16
|
+
"BufferEncoding": true,
|
|
17
|
+
"NodeJS": true
|
|
18
|
+
},
|
|
19
|
+
"extends": [
|
|
20
|
+
"eslint:recommended",
|
|
21
|
+
"standard",
|
|
22
|
+
"plugin:promise/recommended",
|
|
23
|
+
"plugin:jest/recommended",
|
|
24
|
+
"plugin:security/recommended",
|
|
25
|
+
"plugin:prettier/recommended"
|
|
26
|
+
],
|
|
27
|
+
"rules": {
|
|
28
|
+
"camelcase": "off",
|
|
29
|
+
"no-unused-vars": "off",
|
|
30
|
+
"no-empty": "off",
|
|
31
|
+
"@typescript-eslint/no-unused-vars": [
|
|
32
|
+
"error",
|
|
33
|
+
{ "args": "after-used", "argsIgnorePattern": "^_" }
|
|
34
|
+
],
|
|
35
|
+
"@typescript-eslint/no-explicit-any": "warn",
|
|
36
|
+
"simple-import-sort/imports": "error",
|
|
37
|
+
"simple-import-sort/exports": "error",
|
|
38
|
+
"prettier/prettier": ["error", { "singleQuote": true, "trailingComma": "none" }]
|
|
39
|
+
},
|
|
40
|
+
"overrides": [{
|
|
41
|
+
"files": ["**/*.test.ts", "tests/**/*"],
|
|
42
|
+
"rules": {
|
|
43
|
+
"@typescript-eslint/no-explicit-any": "off",
|
|
44
|
+
"security/detect-object-injection": "off",
|
|
45
|
+
"security/detect-unsafe-regex": "off"
|
|
46
|
+
}
|
|
47
|
+
}]
|
|
48
|
+
}
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2021 swe
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
package/dist/cps.d.ts
ADDED
package/dist/cps.js
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.cpsVisit = void 0;
|
|
13
|
+
const greybel_interpreter_1 = require("greybel-interpreter");
|
|
14
|
+
const greyscript_core_1 = require("greyscript-core");
|
|
15
|
+
const miniscript_core_1 = require("miniscript-core");
|
|
16
|
+
const include_1 = require("./operations/include");
|
|
17
|
+
const cpsVisit = (internalCPSVisit, context, stack, item) => __awaiter(void 0, void 0, void 0, function* () {
|
|
18
|
+
const currentTarget = stack[stack.length - 1];
|
|
19
|
+
switch (item.type) {
|
|
20
|
+
case greyscript_core_1.ASTType.ImportCodeExpression: {
|
|
21
|
+
const importExpr = item;
|
|
22
|
+
const target = yield context.handler.resourceHandler.getTargetRelativeTo(currentTarget, importExpr.directory);
|
|
23
|
+
if (stack.includes(target)) {
|
|
24
|
+
console.warn(`Found circular dependency between "${currentTarget}" and "${target}" at line ${item.start.line}. Using noop instead to prevent overflow.`);
|
|
25
|
+
return new greybel_interpreter_1.Noop(item, target);
|
|
26
|
+
}
|
|
27
|
+
const code = yield context.handler.resourceHandler.get(target);
|
|
28
|
+
if (code == null) {
|
|
29
|
+
const range = new miniscript_core_1.ASTRange(item.start, item.end);
|
|
30
|
+
throw new greybel_interpreter_1.PrepareError(`Cannot find native import "${currentTarget}"`, {
|
|
31
|
+
target: currentTarget,
|
|
32
|
+
range
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
try {
|
|
36
|
+
const subVisit = internalCPSVisit.bind(null, internalCPSVisit, context, [
|
|
37
|
+
...stack,
|
|
38
|
+
target
|
|
39
|
+
]);
|
|
40
|
+
const importStatement = yield new include_1.Include(importExpr, currentTarget, target, code).build(subVisit);
|
|
41
|
+
return importStatement;
|
|
42
|
+
}
|
|
43
|
+
catch (err) {
|
|
44
|
+
if (err instanceof greybel_interpreter_1.PrepareError) {
|
|
45
|
+
throw err;
|
|
46
|
+
}
|
|
47
|
+
throw new greybel_interpreter_1.PrepareError(err.message, {
|
|
48
|
+
target,
|
|
49
|
+
range: new miniscript_core_1.ASTRange(item.start, item.end)
|
|
50
|
+
}, err);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
default: {
|
|
54
|
+
return (0, greybel_interpreter_1.defaultCPSVisit)(internalCPSVisit, context, stack, item);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
exports.cpsVisit = cpsVisit;
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Interpreter = exports.cpsVisit = void 0;
|
|
4
|
+
var cps_1 = require("./cps");
|
|
5
|
+
Object.defineProperty(exports, "cpsVisit", { enumerable: true, get: function () { return cps_1.cpsVisit; } });
|
|
6
|
+
var interpreter_1 = require("./interpreter");
|
|
7
|
+
Object.defineProperty(exports, "Interpreter", { enumerable: true, get: function () { return interpreter_1.Interpreter; } });
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Interpreter = void 0;
|
|
4
|
+
const greybel_interpreter_1 = require("greybel-interpreter");
|
|
5
|
+
const greyscript_core_1 = require("greyscript-core");
|
|
6
|
+
const cps_1 = require("./cps");
|
|
7
|
+
class Interpreter extends greybel_interpreter_1.Interpreter {
|
|
8
|
+
setTarget(target) {
|
|
9
|
+
if (this.apiContext !== null && this.apiContext.isPending()) {
|
|
10
|
+
throw new Error('You cannot set a target while a process is running.');
|
|
11
|
+
}
|
|
12
|
+
this.target = target;
|
|
13
|
+
const cpsCtx = new greybel_interpreter_1.CPSContext(target, this.handler);
|
|
14
|
+
this.cps = new greybel_interpreter_1.CPS(cpsCtx, cps_1.cpsVisit);
|
|
15
|
+
this.apiContext = new greybel_interpreter_1.OperationContext({
|
|
16
|
+
target,
|
|
17
|
+
isProtected: true,
|
|
18
|
+
debugger: this.debugger,
|
|
19
|
+
handler: this.handler,
|
|
20
|
+
cps: this.cps,
|
|
21
|
+
environmentVariables: this.environmentVariables
|
|
22
|
+
});
|
|
23
|
+
this.globalContext = this.apiContext.fork({
|
|
24
|
+
type: greybel_interpreter_1.ContextType.Global,
|
|
25
|
+
state: greybel_interpreter_1.ContextState.Default
|
|
26
|
+
});
|
|
27
|
+
return this;
|
|
28
|
+
}
|
|
29
|
+
prepare(code) {
|
|
30
|
+
try {
|
|
31
|
+
const parser = new greyscript_core_1.Parser(code);
|
|
32
|
+
const chunk = parser.parseChunk();
|
|
33
|
+
return this.cps.visit(chunk);
|
|
34
|
+
}
|
|
35
|
+
catch (err) {
|
|
36
|
+
if (err instanceof greybel_interpreter_1.PrepareError) {
|
|
37
|
+
this.handler.errorHandler.raise(err);
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
this.handler.errorHandler.raise(new greybel_interpreter_1.PrepareError(err.message, {
|
|
41
|
+
range: err.range,
|
|
42
|
+
target: this.target
|
|
43
|
+
}));
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
return Promise.resolve(new greybel_interpreter_1.Noop(null));
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
exports.Interpreter = Interpreter;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { CPSVisit, CustomValue, Operation, OperationContext } from 'greybel-interpreter';
|
|
2
|
+
import { ASTBase } from 'miniscript-core';
|
|
3
|
+
export declare class Include extends Operation {
|
|
4
|
+
readonly item: ASTBase;
|
|
5
|
+
newTarget: string;
|
|
6
|
+
code: string;
|
|
7
|
+
chunk: ASTBase;
|
|
8
|
+
top: Operation;
|
|
9
|
+
constructor(item: ASTBase, target: string, newTarget: string, code: string);
|
|
10
|
+
build(visit: CPSVisit): Promise<Operation>;
|
|
11
|
+
handle(ctx: OperationContext): Promise<CustomValue>;
|
|
12
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.Include = void 0;
|
|
13
|
+
const greybel_interpreter_1 = require("greybel-interpreter");
|
|
14
|
+
const greyscript_core_1 = require("greyscript-core");
|
|
15
|
+
class Include extends greybel_interpreter_1.Operation {
|
|
16
|
+
constructor(item, target, newTarget, code) {
|
|
17
|
+
super(null, target);
|
|
18
|
+
this.newTarget = newTarget;
|
|
19
|
+
this.item = item;
|
|
20
|
+
this.code = code;
|
|
21
|
+
}
|
|
22
|
+
build(visit) {
|
|
23
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
24
|
+
const parser = new greyscript_core_1.Parser(this.code);
|
|
25
|
+
this.chunk = parser.parseChunk();
|
|
26
|
+
this.top = yield visit(this.chunk);
|
|
27
|
+
return this;
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
handle(ctx) {
|
|
31
|
+
const importCtx = ctx.fork({
|
|
32
|
+
type: greybel_interpreter_1.ContextType.External,
|
|
33
|
+
state: greybel_interpreter_1.ContextState.Temporary,
|
|
34
|
+
target: this.newTarget
|
|
35
|
+
});
|
|
36
|
+
return this.top.handle(importCtx);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
exports.Include = Include;
|
package/package.json
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "greyscript-interpreter",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Interpreter",
|
|
5
|
+
"main": "dist/index",
|
|
6
|
+
"typings": "dist/index",
|
|
7
|
+
"scripts": {
|
|
8
|
+
"prepublishOnly": "npm run build",
|
|
9
|
+
"build": "npm run clean && tsc -p .",
|
|
10
|
+
"watch": "tsc -w -p .",
|
|
11
|
+
"clean": "rm -rf dist",
|
|
12
|
+
"test": "jest ./tests",
|
|
13
|
+
"lint": "eslint ./src/**/*.ts",
|
|
14
|
+
"lint:fix": "eslint --fix ./src/**/*.ts"
|
|
15
|
+
},
|
|
16
|
+
"repository": {
|
|
17
|
+
"type": "git",
|
|
18
|
+
"url": "git+https://github.com/ayecue/greyscript-interpreter.git"
|
|
19
|
+
},
|
|
20
|
+
"author": {
|
|
21
|
+
"name": "ayecue",
|
|
22
|
+
"email": "soerenwehmeier@googlemail.com"
|
|
23
|
+
},
|
|
24
|
+
"license": "MIT",
|
|
25
|
+
"bugs": {
|
|
26
|
+
"url": "https://github.com/ayecue/greyscript-interpreter/issues"
|
|
27
|
+
},
|
|
28
|
+
"homepage": "https://github.com/ayecue/greyscript-interpreter#readme",
|
|
29
|
+
"devDependencies": {
|
|
30
|
+
"@types/jest": "^27.0.3",
|
|
31
|
+
"@types/node": "^17.0.0",
|
|
32
|
+
"@types/uuid": "^8.3.3",
|
|
33
|
+
"@typescript-eslint/eslint-plugin": "^5.62.0",
|
|
34
|
+
"@typescript-eslint/parser": "^5.62.0",
|
|
35
|
+
"eslint": "^8.17.0",
|
|
36
|
+
"eslint-config-prettier": "^8.5.0",
|
|
37
|
+
"eslint-config-standard": "^17.0.0",
|
|
38
|
+
"eslint-plugin-import": "^2.26.0",
|
|
39
|
+
"eslint-plugin-jest": "^26.5.3",
|
|
40
|
+
"eslint-plugin-node": "^11.1.0",
|
|
41
|
+
"eslint-plugin-prettier": "^4.0.0",
|
|
42
|
+
"eslint-plugin-promise": "^6.0.0",
|
|
43
|
+
"eslint-plugin-security": "^1.5.0",
|
|
44
|
+
"eslint-plugin-simple-import-sort": "^7.0.0",
|
|
45
|
+
"jest": "^27.4.5",
|
|
46
|
+
"nodemon": "^2.0.15",
|
|
47
|
+
"ts-node": "^10.4.0",
|
|
48
|
+
"typescript": "^5.0.4"
|
|
49
|
+
},
|
|
50
|
+
"dependencies": {
|
|
51
|
+
"greyscript-core": "^1.0.1",
|
|
52
|
+
"greybel-interpreter": "^3.0.4"
|
|
53
|
+
},
|
|
54
|
+
"keywords": [
|
|
55
|
+
"greyscript",
|
|
56
|
+
"greyhack"
|
|
57
|
+
]
|
|
58
|
+
}
|