0
0

🧑‍💻 combine variable and scope stack

This commit is contained in:
DrMaxNix 2022-10-02 12:38:04 +02:00
parent 5f8e2996e9
commit c9a39157ca

View File

@ -19,11 +19,11 @@ class Juicescript_runner {
// command counter // command counter
this.counter = 0; this.counter = 0;
// current scope // scope and variable stack
this.scope = null; this.stack = [{
scope: null,
// scope variable stack variable: {}
this.variable_stack = [{}]; }];
// warning and error counter // warning and error counter
this.warning_count = 0; this.warning_count = 0;
@ -112,6 +112,14 @@ class Juicescript_runner {
this.command = this.scope_tree.command[this.counter]; this.command = this.scope_tree.command[this.counter];
} }
/*
GETTER: Return name of current scope (top of stack)
*/
get scope(){
return this.stack[this.stack.length - 1].scope;
}
/* /*
GETTER: Return tree of current scope GETTER: Return tree of current scope
*/ */
@ -314,11 +322,11 @@ class Juicescript_runner {
/**/let is_global = false; /**/let is_global = false;
// get index on stack // get index on stack
let stack_index = this.variable_stack.length - 1; let stack_index = this.stack.length - 1;
if(is_global) stack_index = 0; if(is_global) stack_index = 0;
// get index' full variable list // get index' full variable list
let variable_list = this.variable_stack[stack_index]; let variable_list = this.stack[stack_index].variable;
// try to load value from stack // try to load value from stack
let value = null; let value = null;
@ -380,11 +388,11 @@ class Juicescript_runner {
/**/let is_global = false; /**/let is_global = false;
// get index on stack // get index on stack
let stack_index = this.variable_stack.length - 1; let stack_index = this.stack.length - 1;
if(is_global) stack_index = 0; if(is_global) stack_index = 0;
// get index' full variable list // get index' full variable list
let variable_list = this.variable_stack[stack_index]; let variable_list = this.stack[stack_index].variable;
// set value on stack // set value on stack
variable_list[variable.name] = value; variable_list[variable.name] = value;