|
|
@@ -4,11 +4,39 @@ var PC = 0; |
|
|
|
var PCL = "__PC__"; |
|
|
|
|
|
|
|
|
|
|
|
function StoreVar(env, name, val){ |
|
|
|
let initSet = false; |
|
|
|
if (!(name in Object.keys(env.__vars))){ |
|
|
|
if (env.__parent && env.__parent.hasVar(name)) |
|
|
|
return env.__parent.setVarVal(name, val); |
|
|
|
initSet = true; |
|
|
|
} |
|
|
|
env.__vars[name] = val; |
|
|
|
if (initSet) |
|
|
|
env.emitVarVal(name); |
|
|
|
if (env.__templabels.length > 0){ |
|
|
|
env.__templabels.forEach((l)=>{ |
|
|
|
delete env.__vars[l]; |
|
|
|
delete env.__listeners[l]; |
|
|
|
}); |
|
|
|
env.__templabels = []; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
function StoreTempLabel(env, name, val){ |
|
|
|
env.__vars[name] = val; |
|
|
|
env.__templabels.push(name); |
|
|
|
env.emitVarVal(name); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
class Environment{ |
|
|
|
constructor(parent){ |
|
|
|
this.__parent = (parent instanceof Environment) ? parent : null; |
|
|
|
this.__vars = {}; |
|
|
|
this.__listeners = {}; |
|
|
|
|
|
|
|
this.__templabels = []; |
|
|
|
} |
|
|
|
|
|
|
|
get PC(){return PC;} |
|
|
@@ -49,15 +77,12 @@ class Environment{ |
|
|
|
PC = Math.floor(val); |
|
|
|
return this; |
|
|
|
} |
|
|
|
let initSet = false; |
|
|
|
if (!(name in Object.keys(this.__vars))){ |
|
|
|
if (this.__parent && this.__parent.hasVar(name)) |
|
|
|
return this.__parent.setVarVal(name, val); |
|
|
|
initSet = true; |
|
|
|
if (name === ":"){ |
|
|
|
StoreTempLabel(this, ":" + this.__templabels.length, val); |
|
|
|
} else { |
|
|
|
StoreVar(this, name, val); |
|
|
|
} |
|
|
|
this.__vars[name] = val; |
|
|
|
if (initSet){ |
|
|
|
this.emitVarVal(name); |
|
|
|
|
|
|
|
return this; |
|
|
|
} |
|
|
|
|