VM constructor also accepts valueFunctions
This commit is contained in:
parent
bbdfcdb54a
commit
aa8ecb7cf6
12
src/vm.ts
12
src/vm.ts
|
|
@ -19,15 +19,19 @@ export class VM {
|
||||||
labels: Map<number, string> = new Map()
|
labels: Map<number, string> = new Map()
|
||||||
nativeFunctions: Map<string, NativeFunction> = new Map()
|
nativeFunctions: Map<string, NativeFunction> = new Map()
|
||||||
|
|
||||||
constructor(bytecode: Bytecode, functions?: Record<string, TypeScriptFunction>) {
|
constructor(bytecode: Bytecode, nativeFunctions?: Record<string, TypeScriptFunction>, valueFunctions?: Record<string, NativeFunction>) {
|
||||||
this.instructions = bytecode.instructions
|
this.instructions = bytecode.instructions
|
||||||
this.constants = bytecode.constants
|
this.constants = bytecode.constants
|
||||||
this.labels = bytecode.labels || new Map()
|
this.labels = bytecode.labels || new Map()
|
||||||
this.scope = new Scope()
|
this.scope = new Scope()
|
||||||
|
|
||||||
if (functions)
|
if (nativeFunctions)
|
||||||
for (const name of Object.keys(functions))
|
for (const name of Object.keys(nativeFunctions))
|
||||||
this.registerFunction(name, functions[name]!)
|
this.registerFunction(name, nativeFunctions[name]!)
|
||||||
|
|
||||||
|
if (valueFunctions)
|
||||||
|
for (const name of Object.keys(valueFunctions))
|
||||||
|
this.registerValueFunction(name, valueFunctions[name]!)
|
||||||
}
|
}
|
||||||
|
|
||||||
async call(name: string, ...args: any) {
|
async call(name: string, ...args: any) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user