lowleveljs
Version:
1. 使用`@babel/parser`解析出js代码的语法树 2. 把所有的功能语句编译成最基础的操作指令列表 3. 编写解释器来运行这些基础操作指令
17 lines (16 loc) • 406 B
JavaScript
const {compile, run}=require(__dirname+'/../..')
const maskstr=0
const bindVars={
A: 2,
B: 3,
shared: {}, // 共享对象可实现内外交互
}
const code=`
shared.G=function(){
return A*B
}`
const {BIN, GVARS}=compile(maskstr, code)
console.log('检测到的全局变量:', GVARS)
console.log('编译结果:', BIN)
run(maskstr, BIN, bindVars)
console.log(bindVars.shared.G())