sptc 0.0.24 → 0.0.26
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/engine/index.js +11 -0
- package/engine/interpreter-macro.js +2 -1
- package/engine/interpreter.js +12 -0
- package/package.json +2 -2
- package/tests/ctx/1.js +6 -0
- package/tests/ctx/a.js +3 -0
- package/tests/ctx/a.s +4 -0
- package/tests/inc_js/1.s +3 -0
- package/tests/inc_js/a.js +3 -0
- package/utils/compileFile.js +1 -1
package/engine/index.js
CHANGED
|
@@ -24,6 +24,7 @@ function executeSptcFile(filename, payload, option={}) {
|
|
|
24
24
|
const [ctx0, vm]=Compiler.compileSptcFile(filename, _option)
|
|
25
25
|
const [ctx, priv]=Interpreter.buildContext({...payload, ...ctx0}, option)
|
|
26
26
|
Interpreter.executeVm(vm, ctx, priv)
|
|
27
|
+
return ctx
|
|
27
28
|
}
|
|
28
29
|
|
|
29
30
|
function executeSptcFileEx(...x) {
|
|
@@ -53,6 +54,14 @@ function executeSptcMacroFile(filename, config, mockContent) {
|
|
|
53
54
|
return InterpreterMacro.executeMacroContext(ctx, ast)
|
|
54
55
|
}
|
|
55
56
|
|
|
57
|
+
function includeJsFile(filename, payload) {
|
|
58
|
+
return Interpreter.buildContext({}, {})[0].include_js(filename, payload)
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function includeSptcFile(filename, payload) {
|
|
62
|
+
return executeSptcFile(filename, payload)
|
|
63
|
+
}
|
|
64
|
+
|
|
56
65
|
module.exports={
|
|
57
66
|
...Compiler,
|
|
58
67
|
...Interpreter,
|
|
@@ -61,5 +70,7 @@ module.exports={
|
|
|
61
70
|
executeSptcFile,
|
|
62
71
|
executeSptcFileEx,
|
|
63
72
|
executeSptcMacroFile,
|
|
73
|
+
includeSptcFile,
|
|
74
|
+
includeJsFile,
|
|
64
75
|
version: require('../package.json').version
|
|
65
76
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
const {compileSptcMacroFile, MACRO_TYPES}=require('./compiler-macro')
|
|
2
|
+
const path=require('path')
|
|
2
3
|
|
|
3
4
|
const {
|
|
4
5
|
O_IFDEF,
|
|
@@ -58,7 +59,7 @@ function execute(ctx, ast) {
|
|
|
58
59
|
}else if(p.type===O_INCLUDE) {
|
|
59
60
|
const filename=path.resolve(ctx.filename+'/..', p.include)
|
|
60
61
|
const nctx=Object.assign({}, ctx, {filename})
|
|
61
|
-
ret+=
|
|
62
|
+
ret+=executeMacroContext(nctx)
|
|
62
63
|
}else{
|
|
63
64
|
throw new Error('unsupported node: '+JSON.stringify(p))
|
|
64
65
|
}
|
package/engine/interpreter.js
CHANGED
|
@@ -277,6 +277,18 @@ function buildContext(ctx0, option) {
|
|
|
277
277
|
})
|
|
278
278
|
}
|
|
279
279
|
|
|
280
|
+
ctx.include_js=(inc_filename, inc_payload={})=>{
|
|
281
|
+
const inc=path.resolve(ctx0.__dirname, inc_filename)
|
|
282
|
+
const jsvm=Utils.compileFile(inc, {
|
|
283
|
+
compileFunc: code=>new vm.Script(code+'; Symbol()[0]=_=>0', inc)
|
|
284
|
+
})
|
|
285
|
+
const jsctx={
|
|
286
|
+
...inc_payload,
|
|
287
|
+
}
|
|
288
|
+
jsvm.runInNewContext(jsctx)
|
|
289
|
+
return jsctx
|
|
290
|
+
}
|
|
291
|
+
|
|
280
292
|
ctx.__autoload=fn=>{
|
|
281
293
|
priv.__autoload_func=fn
|
|
282
294
|
}
|
package/package.json
CHANGED
package/tests/ctx/1.js
ADDED
package/tests/ctx/a.js
ADDED
package/tests/ctx/a.s
ADDED
package/tests/inc_js/1.s
ADDED