This commit is contained in:
Valk Richard Li 2020-12-01 19:35:32 +08:00
parent f336e5c3ae
commit 33e544387e
3 changed files with 705 additions and 727 deletions

View File

@ -18,50 +18,50 @@
// declaration of builtin functions // declaration of builtin functions
// to add new builtin function,declare it here and write the definition below // to add new builtin function,declare it here and write the definition below
int builtin_print(int); int builtin_print(int,nasal_virtual_machine&);
int builtin_append(int); int builtin_append(int,nasal_virtual_machine&);
int builtin_setsize(int); int builtin_setsize(int,nasal_virtual_machine&);
int builtin_system(int); int builtin_system(int,nasal_virtual_machine&);
int builtin_input(int); int builtin_input(int,nasal_virtual_machine&);
int builtin_sleep(int); int builtin_sleep(int,nasal_virtual_machine&);
int builtin_finput(int); int builtin_finput(int,nasal_virtual_machine&);
int builtin_foutput(int); int builtin_foutput(int,nasal_virtual_machine&);
int builtin_split(int); int builtin_split(int,nasal_virtual_machine&);
int builtin_rand(int); int builtin_rand(int,nasal_virtual_machine&);
int builtin_id(int); int builtin_id(int,nasal_virtual_machine&);
int builtin_int(int); int builtin_int(int,nasal_virtual_machine&);
int builtin_num(int); int builtin_num(int,nasal_virtual_machine&);
int builtin_pop(int); int builtin_pop(int,nasal_virtual_machine&);
int builtin_str(int); int builtin_str(int,nasal_virtual_machine&);
int builtin_size(int); int builtin_size(int,nasal_virtual_machine&);
int builtin_xor(int); int builtin_xor(int,nasal_virtual_machine&);
int builtin_and(int); int builtin_and(int,nasal_virtual_machine&);
int builtin_or(int); int builtin_or(int,nasal_virtual_machine&);
int builtin_nand(int); int builtin_nand(int,nasal_virtual_machine&);
int builtin_not(int); int builtin_not(int,nasal_virtual_machine&);
int builtin_sin(int); int builtin_sin(int,nasal_virtual_machine&);
int builtin_cos(int); int builtin_cos(int,nasal_virtual_machine&);
int builtin_tan(int); int builtin_tan(int,nasal_virtual_machine&);
int builtin_exp(int); int builtin_exp(int,nasal_virtual_machine&);
int builtin_ln(int); int builtin_ln(int,nasal_virtual_machine&);
int builtin_sqrt(int); int builtin_sqrt(int,nasal_virtual_machine&);
int builtin_atan2(int); int builtin_atan2(int,nasal_virtual_machine&);
int builtin_time(int); int builtin_time(int,nasal_virtual_machine&);
int builtin_contains(int); int builtin_contains(int,nasal_virtual_machine&);
int builtin_delete(int); int builtin_delete(int,nasal_virtual_machine&);
int builtin_getkeys(int); int builtin_getkeys(int,nasal_virtual_machine&);
int builtin_import(int); int builtin_import(int,nasal_virtual_machine&);
int builtin_die_state;// used in builtin_die int builtin_die_state;// used in builtin_die
int builtin_die(int); int builtin_die(int,nasal_virtual_machine&);
int builtin_type(int); int builtin_type(int,nasal_virtual_machine&);
int builtin_substr(int); int builtin_substr(int,nasal_virtual_machine&);
// register builtin function's name and it's address here in this table below // register builtin function's name and it's address here in this table below
// this table must and with {"",NULL} // this table must and with {"",NULL}
struct FUNC_TABLE struct FUNC_TABLE
{ {
std::string func_name; std::string func_name;
int (*func_pointer)(int x); int (*func_pointer)(int x,nasal_virtual_machine& nasal_vm);
} builtin_func_table[]= } builtin_func_table[]=
{ {
{"nasal_call_builtin_std_cout", builtin_print}, {"nasal_call_builtin_std_cout", builtin_print},
@ -103,7 +103,7 @@ struct FUNC_TABLE
{"", NULL} {"", NULL}
}; };
int builtin_print(int local_scope_addr) int builtin_print(int local_scope_addr,nasal_virtual_machine& nasal_vm)
{ {
// get arguments // get arguments
int vector_value_addr=in_builtin_find("elements"); int vector_value_addr=in_builtin_find("elements");
@ -133,7 +133,7 @@ int builtin_print(int local_scope_addr)
int ret_addr=nasal_vm.gc_alloc(vm_nil); int ret_addr=nasal_vm.gc_alloc(vm_nil);
return ret_addr; return ret_addr;
} }
int builtin_append(int local_scope_addr) int builtin_append(int local_scope_addr,nasal_virtual_machine& nasal_vm)
{ {
int vector_value_addr=in_builtin_find("vector"); int vector_value_addr=in_builtin_find("vector");
int elem_value_addr=in_builtin_find("elements"); int elem_value_addr=in_builtin_find("elements");
@ -159,7 +159,7 @@ int builtin_append(int local_scope_addr)
int ret_addr=nasal_vm.gc_alloc(vm_nil); int ret_addr=nasal_vm.gc_alloc(vm_nil);
return ret_addr; return ret_addr;
} }
int builtin_setsize(int local_scope_addr) int builtin_setsize(int local_scope_addr,nasal_virtual_machine& nasal_vm)
{ {
int vector_value_addr=in_builtin_find("vector"); int vector_value_addr=in_builtin_find("vector");
int size_value_addr=in_builtin_find("size"); int size_value_addr=in_builtin_find("size");
@ -217,7 +217,7 @@ int builtin_setsize(int local_scope_addr)
return ret_addr; return ret_addr;
} }
int builtin_system(int local_scope_addr) int builtin_system(int local_scope_addr,nasal_virtual_machine& nasal_vm)
{ {
int str_value_addr=in_builtin_find("str"); int str_value_addr=in_builtin_find("str");
if(str_value_addr<0 || nasal_vm.gc_get(str_value_addr).get_type()!=vm_string) if(str_value_addr<0 || nasal_vm.gc_get(str_value_addr).get_type()!=vm_string)
@ -237,7 +237,7 @@ int builtin_system(int local_scope_addr)
return ret_addr; return ret_addr;
} }
int builtin_input(int local_scope_addr) int builtin_input(int local_scope_addr,nasal_virtual_machine& nasal_vm)
{ {
int ret_addr=nasal_vm.gc_alloc(vm_string); int ret_addr=nasal_vm.gc_alloc(vm_string);
std::string str; std::string str;
@ -246,7 +246,7 @@ int builtin_input(int local_scope_addr)
return ret_addr; return ret_addr;
} }
int builtin_sleep(int local_scope_addr) int builtin_sleep(int local_scope_addr,nasal_virtual_machine& nasal_vm)
{ {
int value_addr=in_builtin_find("duration"); int value_addr=in_builtin_find("duration");
if(value_addr<0 || (nasal_vm.gc_get(value_addr).get_type()!=vm_string && nasal_vm.gc_get(value_addr).get_type()!=vm_number)) if(value_addr<0 || (nasal_vm.gc_get(value_addr).get_type()!=vm_string && nasal_vm.gc_get(value_addr).get_type()!=vm_number))
@ -272,7 +272,7 @@ int builtin_sleep(int local_scope_addr)
return ret_addr; return ret_addr;
} }
int builtin_finput(int local_scope_addr) int builtin_finput(int local_scope_addr,nasal_virtual_machine& nasal_vm)
{ {
int value_addr=in_builtin_find("filename"); int value_addr=in_builtin_find("filename");
if(value_addr<0 || nasal_vm.gc_get(value_addr).get_type()!=vm_string) if(value_addr<0 || nasal_vm.gc_get(value_addr).get_type()!=vm_string)
@ -299,7 +299,7 @@ int builtin_finput(int local_scope_addr)
return ret_addr; return ret_addr;
} }
int builtin_foutput(int local_scope_addr) int builtin_foutput(int local_scope_addr,nasal_virtual_machine& nasal_vm)
{ {
int value_addr=in_builtin_find("filename"); int value_addr=in_builtin_find("filename");
int str_value_addr=in_builtin_find("str"); int str_value_addr=in_builtin_find("str");
@ -322,7 +322,7 @@ int builtin_foutput(int local_scope_addr)
return ret_addr; return ret_addr;
} }
int builtin_split(int local_scope_addr) int builtin_split(int local_scope_addr,nasal_virtual_machine& nasal_vm)
{ {
int delimeter_value_addr=in_builtin_find("delimeter"); int delimeter_value_addr=in_builtin_find("delimeter");
int string_value_addr=in_builtin_find("string"); int string_value_addr=in_builtin_find("string");
@ -389,7 +389,7 @@ int builtin_split(int local_scope_addr)
} }
return ret_addr; return ret_addr;
} }
int builtin_rand(int local_scope_addr) int builtin_rand(int local_scope_addr,nasal_virtual_machine& nasal_vm)
{ {
int value_addr=in_builtin_find("seed"); int value_addr=in_builtin_find("seed");
if(value_addr<0 || (nasal_vm.gc_get(value_addr).get_type()!=vm_number && nasal_vm.gc_get(value_addr).get_type()!=vm_nil)) if(value_addr<0 || (nasal_vm.gc_get(value_addr).get_type()!=vm_number && nasal_vm.gc_get(value_addr).get_type()!=vm_nil))
@ -411,7 +411,7 @@ int builtin_rand(int local_scope_addr)
nasal_vm.gc_get(ret_addr).set_number(num); nasal_vm.gc_get(ret_addr).set_number(num);
return ret_addr; return ret_addr;
} }
int builtin_id(int local_scope_addr) int builtin_id(int local_scope_addr,nasal_virtual_machine& nasal_vm)
{ {
int value_addr=in_builtin_find("thing"); int value_addr=in_builtin_find("thing");
if(value_addr<0) if(value_addr<0)
@ -423,7 +423,7 @@ int builtin_id(int local_scope_addr)
nasal_vm.gc_get(ret_addr).set_number((double)value_addr); nasal_vm.gc_get(ret_addr).set_number((double)value_addr);
return ret_addr; return ret_addr;
} }
int builtin_int(int local_scope_addr) int builtin_int(int local_scope_addr,nasal_virtual_machine& nasal_vm)
{ {
int value_addr=in_builtin_find("value"); int value_addr=in_builtin_find("value");
if(value_addr<0 || nasal_vm.gc_get(value_addr).get_type()!=vm_number) if(value_addr<0 || nasal_vm.gc_get(value_addr).get_type()!=vm_number)
@ -436,7 +436,7 @@ int builtin_int(int local_scope_addr)
nasal_vm.gc_get(ret_addr).set_number((double)number); nasal_vm.gc_get(ret_addr).set_number((double)number);
return ret_addr; return ret_addr;
} }
int builtin_num(int local_scope_addr) int builtin_num(int local_scope_addr,nasal_virtual_machine& nasal_vm)
{ {
int value_addr=in_builtin_find("value"); int value_addr=in_builtin_find("value");
if(value_addr<0 || !in_builtin_check(value_addr,vm_string)) if(value_addr<0 || !in_builtin_check(value_addr,vm_string))
@ -449,7 +449,7 @@ int builtin_num(int local_scope_addr)
nasal_vm.gc_get(ret_addr).set_number(trans_string_to_number(str)); nasal_vm.gc_get(ret_addr).set_number(trans_string_to_number(str));
return ret_addr; return ret_addr;
} }
int builtin_pop(int local_scope_addr) int builtin_pop(int local_scope_addr,nasal_virtual_machine& nasal_vm)
{ {
int value_addr=in_builtin_find("vector"); int value_addr=in_builtin_find("vector");
if(value_addr<0 || nasal_vm.gc_get(value_addr).get_type()!=vm_vector) if(value_addr<0 || nasal_vm.gc_get(value_addr).get_type()!=vm_vector)
@ -460,7 +460,7 @@ int builtin_pop(int local_scope_addr)
int ret_addr=nasal_vm.gc_get(value_addr).get_vector().del_elem(); int ret_addr=nasal_vm.gc_get(value_addr).get_vector().del_elem();
return ret_addr; return ret_addr;
} }
int builtin_str(int local_scope_addr) int builtin_str(int local_scope_addr,nasal_virtual_machine& nasal_vm)
{ {
int value_addr=in_builtin_find("number"); int value_addr=in_builtin_find("number");
if(value_addr<0 || nasal_vm.gc_get(value_addr).get_type()!=vm_number) if(value_addr<0 || nasal_vm.gc_get(value_addr).get_type()!=vm_number)
@ -473,7 +473,7 @@ int builtin_str(int local_scope_addr)
nasal_vm.gc_get(ret_addr).set_string(trans_number_to_string(number)); nasal_vm.gc_get(ret_addr).set_string(trans_number_to_string(number));
return ret_addr; return ret_addr;
} }
int builtin_size(int local_scope_addr) int builtin_size(int local_scope_addr,nasal_virtual_machine& nasal_vm)
{ {
int value_addr=in_builtin_find("object"); int value_addr=in_builtin_find("object");
if(value_addr<0) if(value_addr<0)
@ -503,7 +503,7 @@ int builtin_size(int local_scope_addr)
} }
return ret_addr; return ret_addr;
} }
int builtin_xor(int local_scope_addr) int builtin_xor(int local_scope_addr,nasal_virtual_machine& nasal_vm)
{ {
int a_addr=in_builtin_find("a"); int a_addr=in_builtin_find("a");
int b_addr=in_builtin_find("b"); int b_addr=in_builtin_find("b");
@ -523,7 +523,7 @@ int builtin_xor(int local_scope_addr)
nasal_vm.gc_get(ret_addr).set_number((double)(number_a^number_b)); nasal_vm.gc_get(ret_addr).set_number((double)(number_a^number_b));
return ret_addr; return ret_addr;
} }
int builtin_and(int local_scope_addr) int builtin_and(int local_scope_addr,nasal_virtual_machine& nasal_vm)
{ {
int a_addr=in_builtin_find("a"); int a_addr=in_builtin_find("a");
int b_addr=in_builtin_find("b"); int b_addr=in_builtin_find("b");
@ -543,7 +543,7 @@ int builtin_and(int local_scope_addr)
nasal_vm.gc_get(ret_addr).set_number((double)(number_a&number_b)); nasal_vm.gc_get(ret_addr).set_number((double)(number_a&number_b));
return ret_addr; return ret_addr;
} }
int builtin_or(int local_scope_addr) int builtin_or(int local_scope_addr,nasal_virtual_machine& nasal_vm)
{ {
int a_addr=in_builtin_find("a"); int a_addr=in_builtin_find("a");
int b_addr=in_builtin_find("b"); int b_addr=in_builtin_find("b");
@ -563,7 +563,7 @@ int builtin_or(int local_scope_addr)
nasal_vm.gc_get(ret_addr).set_number((double)(number_a|number_b)); nasal_vm.gc_get(ret_addr).set_number((double)(number_a|number_b));
return ret_addr; return ret_addr;
} }
int builtin_nand(int local_scope_addr) int builtin_nand(int local_scope_addr,nasal_virtual_machine& nasal_vm)
{ {
int a_addr=in_builtin_find("a"); int a_addr=in_builtin_find("a");
int b_addr=in_builtin_find("b"); int b_addr=in_builtin_find("b");
@ -583,7 +583,7 @@ int builtin_nand(int local_scope_addr)
nasal_vm.gc_get(ret_addr).set_number((double)(~(number_a&number_b))); nasal_vm.gc_get(ret_addr).set_number((double)(~(number_a&number_b)));
return ret_addr; return ret_addr;
} }
int builtin_not(int local_scope_addr) int builtin_not(int local_scope_addr,nasal_virtual_machine& nasal_vm)
{ {
int a_addr=in_builtin_find("a"); int a_addr=in_builtin_find("a");
if(a_addr<0 || nasal_vm.gc_get(a_addr).get_type()!=vm_number) if(a_addr<0 || nasal_vm.gc_get(a_addr).get_type()!=vm_number)
@ -596,7 +596,7 @@ int builtin_not(int local_scope_addr)
nasal_vm.gc_get(ret_addr).set_number((double)(~number)); nasal_vm.gc_get(ret_addr).set_number((double)(~number));
return ret_addr; return ret_addr;
} }
int builtin_sin(int local_scope_addr) int builtin_sin(int local_scope_addr,nasal_virtual_machine& nasal_vm)
{ {
int value_addr=in_builtin_find("x"); int value_addr=in_builtin_find("x");
if(value_addr<0 || nasal_vm.gc_get(value_addr).get_type()!=vm_number) if(value_addr<0 || nasal_vm.gc_get(value_addr).get_type()!=vm_number)
@ -609,7 +609,7 @@ int builtin_sin(int local_scope_addr)
nasal_vm.gc_get(ret_addr).set_number(sin(number)); nasal_vm.gc_get(ret_addr).set_number(sin(number));
return ret_addr; return ret_addr;
} }
int builtin_cos(int local_scope_addr) int builtin_cos(int local_scope_addr,nasal_virtual_machine& nasal_vm)
{ {
int value_addr=in_builtin_find("x"); int value_addr=in_builtin_find("x");
if(value_addr<0 || nasal_vm.gc_get(value_addr).get_type()!=vm_number) if(value_addr<0 || nasal_vm.gc_get(value_addr).get_type()!=vm_number)
@ -622,7 +622,7 @@ int builtin_cos(int local_scope_addr)
nasal_vm.gc_get(ret_addr).set_number(cos(number)); nasal_vm.gc_get(ret_addr).set_number(cos(number));
return ret_addr; return ret_addr;
} }
int builtin_tan(int local_scope_addr) int builtin_tan(int local_scope_addr,nasal_virtual_machine& nasal_vm)
{ {
int value_addr=in_builtin_find("x"); int value_addr=in_builtin_find("x");
if(value_addr<0 || nasal_vm.gc_get(value_addr).get_type()!=vm_number) if(value_addr<0 || nasal_vm.gc_get(value_addr).get_type()!=vm_number)
@ -635,7 +635,7 @@ int builtin_tan(int local_scope_addr)
nasal_vm.gc_get(ret_addr).set_number(tan(number)); nasal_vm.gc_get(ret_addr).set_number(tan(number));
return ret_addr; return ret_addr;
} }
int builtin_exp(int local_scope_addr) int builtin_exp(int local_scope_addr,nasal_virtual_machine& nasal_vm)
{ {
int value_addr=in_builtin_find("x"); int value_addr=in_builtin_find("x");
if(value_addr<0 || nasal_vm.gc_get(value_addr).get_type()!=vm_number) if(value_addr<0 || nasal_vm.gc_get(value_addr).get_type()!=vm_number)
@ -648,7 +648,7 @@ int builtin_exp(int local_scope_addr)
nasal_vm.gc_get(ret_addr).set_number(exp(number)); nasal_vm.gc_get(ret_addr).set_number(exp(number));
return ret_addr; return ret_addr;
} }
int builtin_ln(int local_scope_addr) int builtin_ln(int local_scope_addr,nasal_virtual_machine& nasal_vm)
{ {
int value_addr=in_builtin_find("x"); int value_addr=in_builtin_find("x");
if(value_addr<0 || nasal_vm.gc_get(value_addr).get_type()!=vm_number) if(value_addr<0 || nasal_vm.gc_get(value_addr).get_type()!=vm_number)
@ -661,7 +661,7 @@ int builtin_ln(int local_scope_addr)
nasal_vm.gc_get(ret_addr).set_number(log(number)/log(2.7182818284590452354)); nasal_vm.gc_get(ret_addr).set_number(log(number)/log(2.7182818284590452354));
return ret_addr; return ret_addr;
} }
int builtin_sqrt(int local_scope_addr) int builtin_sqrt(int local_scope_addr,nasal_virtual_machine& nasal_vm)
{ {
int value_addr=in_builtin_find("x"); int value_addr=in_builtin_find("x");
if(value_addr<0 || nasal_vm.gc_get(value_addr).get_type()!=vm_number) if(value_addr<0 || nasal_vm.gc_get(value_addr).get_type()!=vm_number)
@ -674,7 +674,7 @@ int builtin_sqrt(int local_scope_addr)
nasal_vm.gc_get(ret_addr).set_number(sqrt(number)); nasal_vm.gc_get(ret_addr).set_number(sqrt(number));
return ret_addr; return ret_addr;
} }
int builtin_atan2(int local_scope_addr) int builtin_atan2(int local_scope_addr,nasal_virtual_machine& nasal_vm)
{ {
int x_value_addr=in_builtin_find("x"); int x_value_addr=in_builtin_find("x");
int y_value_addr=in_builtin_find("y"); int y_value_addr=in_builtin_find("y");
@ -694,7 +694,7 @@ int builtin_atan2(int local_scope_addr)
nasal_vm.gc_get(ret_addr).set_number(atan2(y,x)); nasal_vm.gc_get(ret_addr).set_number(atan2(y,x));
return ret_addr; return ret_addr;
} }
int builtin_time(int local_scope_addr) int builtin_time(int local_scope_addr,nasal_virtual_machine& nasal_vm)
{ {
int value_addr=in_builtin_find("begin_time"); int value_addr=in_builtin_find("begin_time");
if(value_addr<0 || nasal_vm.gc_get(value_addr).get_type()!=vm_number) if(value_addr<0 || nasal_vm.gc_get(value_addr).get_type()!=vm_number)
@ -707,7 +707,7 @@ int builtin_time(int local_scope_addr)
nasal_vm.gc_get(ret_addr).set_number((double)time(&begin_time)); nasal_vm.gc_get(ret_addr).set_number((double)time(&begin_time));
return ret_addr; return ret_addr;
} }
int builtin_contains(int local_scope_addr) int builtin_contains(int local_scope_addr,nasal_virtual_machine& nasal_vm)
{ {
int hash_addr=in_builtin_find("hash"); int hash_addr=in_builtin_find("hash");
int key_addr=in_builtin_find("key"); int key_addr=in_builtin_find("key");
@ -727,7 +727,7 @@ int builtin_contains(int local_scope_addr)
nasal_vm.gc_get(ret_addr).set_number((double)contains); nasal_vm.gc_get(ret_addr).set_number((double)contains);
return ret_addr; return ret_addr;
} }
int builtin_delete(int local_scope_addr) int builtin_delete(int local_scope_addr,nasal_virtual_machine& nasal_vm)
{ {
int hash_addr=in_builtin_find("hash"); int hash_addr=in_builtin_find("hash");
int key_addr=in_builtin_find("key"); int key_addr=in_builtin_find("key");
@ -746,7 +746,7 @@ int builtin_delete(int local_scope_addr)
int ret_addr=nasal_vm.gc_alloc(vm_nil); int ret_addr=nasal_vm.gc_alloc(vm_nil);
return ret_addr; return ret_addr;
} }
int builtin_getkeys(int local_scope_addr) int builtin_getkeys(int local_scope_addr,nasal_virtual_machine& nasal_vm)
{ {
int hash_addr=in_builtin_find("hash"); int hash_addr=in_builtin_find("hash");
if(hash_addr<0 || !in_builtin_check(hash_addr,vm_hash)) if(hash_addr<0 || !in_builtin_check(hash_addr,vm_hash))
@ -757,7 +757,7 @@ int builtin_getkeys(int local_scope_addr)
int ret_addr=nasal_vm.gc_get(hash_addr).get_hash().get_keys(); int ret_addr=nasal_vm.gc_get(hash_addr).get_hash().get_keys();
return ret_addr; return ret_addr;
} }
int builtin_import(int local_scope_addr) int builtin_import(int local_scope_addr,nasal_virtual_machine& nasal_vm)
{ {
// this function is used in preprocessing. // this function is used in preprocessing.
// this function will return nothing when running. // this function will return nothing when running.
@ -765,7 +765,7 @@ int builtin_import(int local_scope_addr)
int ret_addr=nasal_vm.gc_alloc(vm_nil); int ret_addr=nasal_vm.gc_alloc(vm_nil);
return ret_addr; return ret_addr;
} }
int builtin_die(int local_scope_addr) int builtin_die(int local_scope_addr,nasal_virtual_machine& nasal_vm)
{ {
int str_addr=in_builtin_find("str"); int str_addr=in_builtin_find("str");
if(str_addr<0 || !in_builtin_check(str_addr,vm_string)) if(str_addr<0 || !in_builtin_check(str_addr,vm_string))
@ -778,7 +778,7 @@ int builtin_die(int local_scope_addr)
int ret_addr=nasal_vm.gc_alloc(vm_nil); int ret_addr=nasal_vm.gc_alloc(vm_nil);
return ret_addr; return ret_addr;
} }
int builtin_type(int local_scope_addr) int builtin_type(int local_scope_addr,nasal_virtual_machine& nasal_vm)
{ {
int value_addr=in_builtin_find("object"); int value_addr=in_builtin_find("object");
if(value_addr<0) if(value_addr<0)
@ -799,7 +799,7 @@ int builtin_type(int local_scope_addr)
} }
return ret_addr; return ret_addr;
} }
int builtin_substr(int local_scope_addr) int builtin_substr(int local_scope_addr,nasal_virtual_machine& nasal_vm)
{ {
int str_addr=in_builtin_find("str"); int str_addr=in_builtin_find("str");
int begin_addr=in_builtin_find("begin"); int begin_addr=in_builtin_find("begin");

File diff suppressed because it is too large Load Diff

View File

@ -13,7 +13,8 @@ enum runtime_returned_state
class nasal_runtime class nasal_runtime
{ {
private: private:
std::map<std::string,int (*)(int x)> builtin_func_hashmap; nasal_virtual_machine nasal_vm;
std::map<std::string,int (*)(int x,nasal_virtual_machine& vm)> builtin_func_hashmap;
// function_return_address is an address in garbage_collector_memory // function_return_address is an address in garbage_collector_memory
int function_returned_address; int function_returned_address;
// global_scope_address is an address in garbage_collector_memory // global_scope_address is an address in garbage_collector_memory
@ -59,6 +60,19 @@ private:
int call_vector_mem(nasal_ast&,int,int); int call_vector_mem(nasal_ast&,int,int);
int call_hash_mem(nasal_ast&,int,int); int call_hash_mem(nasal_ast&,int,int);
// calculate scalars // calculate scalars
int nasal_scalar_add(int,int);
int nasal_scalar_sub(int,int);
int nasal_scalar_mult(int,int);
int nasal_scalar_div(int,int);
int nasal_scalar_link(int,int);
int nasal_scalar_unary_sub(int);
int nasal_scalar_unary_not(int);
int nasal_scalar_cmp_equal(int,int);
int nasal_scalar_cmp_not_equal(int,int);
int nasal_scalar_cmp_less(int,int);
int nasal_scalar_cmp_greater(int,int);
int nasal_scalar_cmp_less_or_equal(int,int);
int nasal_scalar_cmp_greater_or_equal(int,int);
int calculation(nasal_ast&,int); int calculation(nasal_ast&,int);
void definition(nasal_ast&,int); void definition(nasal_ast&,int);
void multi_assignment(nasal_ast&,int); void multi_assignment(nasal_ast&,int);
@ -773,9 +787,9 @@ int nasal_runtime::call_function(nasal_ast& node,std::string func_name,int base_
int run_closure_addr=reference_of_func.get_closure_addr(); int run_closure_addr=reference_of_func.get_closure_addr();
nasal_closure& run_closure=nasal_vm.gc_get(run_closure_addr).get_closure(); nasal_closure& run_closure=nasal_vm.gc_get(run_closure_addr).get_closure();
run_closure.add_scope(); run_closure.add_scope();
// set hash.me
if(last_call_hash_addr>=0) if(last_call_hash_addr>=0)
{ {
// set hash.me
nasal_vm.add_reference(last_call_hash_addr); nasal_vm.add_reference(last_call_hash_addr);
run_closure.add_new_value("me",last_call_hash_addr); run_closure.add_new_value("me",last_call_hash_addr);
} }
@ -952,7 +966,7 @@ int nasal_runtime::call_builtin_function(std::string val_name,int local_scope_ad
int builtin_func_num=-1; int builtin_func_num=-1;
if(builtin_func_hashmap.find(val_name)!=builtin_func_hashmap.end()) if(builtin_func_hashmap.find(val_name)!=builtin_func_hashmap.end())
{ {
ret_value_addr=(*builtin_func_hashmap[val_name])(local_scope_addr); ret_value_addr=(*builtin_func_hashmap[val_name])(local_scope_addr,nasal_vm);
error+=builtin_die_state; error+=builtin_die_state;
} }
return ret_value_addr; return ret_value_addr;
@ -1062,6 +1076,449 @@ int nasal_runtime::call_hash_mem(nasal_ast& node,int base_mem_addr,int local_sco
int ret_mem_addr=nasal_vm.gc_get(base_value_addr).get_hash().get_mem_address(node.get_str()); int ret_mem_addr=nasal_vm.gc_get(base_value_addr).get_hash().get_mem_address(node.get_str());
return ret_mem_addr; return ret_mem_addr;
} }
int nasal_runtime::nasal_scalar_add(int a_scalar_addr,int b_scalar_addr)
{
if(a_scalar_addr<0 || b_scalar_addr<0)
{
std::cout<<">> [vm] scalar_add: memory returned an invalid address.\n";
return -1;
}
nasal_scalar& a_ref=nasal_vm.gc_get(a_scalar_addr);
nasal_scalar& b_ref=nasal_vm.gc_get(b_scalar_addr);
int a_ref_type=a_ref.get_type();
int b_ref_type=b_ref.get_type();
double a_num=(1/0.0)+(-1/0.0);
double b_num=(1/0.0)+(-1/0.0);
if(a_ref_type==vm_number)
a_num=a_ref.get_number();
else if(a_ref_type==vm_string)
a_num=trans_string_to_number(a_ref.get_string());
if(b_ref_type==vm_number)
b_num=b_ref.get_number();
else if(b_ref_type==vm_string)
b_num=trans_string_to_number(b_ref.get_string());
int new_value_address=nasal_vm.gc_alloc(vm_number);
nasal_vm.gc_get(new_value_address).set_number(a_num+b_num);
return new_value_address;
}
int nasal_runtime::nasal_scalar_sub(int a_scalar_addr,int b_scalar_addr)
{
if(a_scalar_addr<0 || b_scalar_addr<0)
{
std::cout<<">> [vm] scalar_sub: memory returned an invalid address.\n";
return -1;
}
nasal_scalar& a_ref=nasal_vm.gc_get(a_scalar_addr);
nasal_scalar& b_ref=nasal_vm.gc_get(b_scalar_addr);
int a_ref_type=a_ref.get_type();
int b_ref_type=b_ref.get_type();
double a_num=(1/0.0)+(-1/0.0);
double b_num=(1/0.0)+(-1/0.0);
if(a_ref_type==vm_number)
a_num=a_ref.get_number();
else if(a_ref_type==vm_string)
a_num=trans_string_to_number(a_ref.get_string());
if(b_ref_type==vm_number)
b_num=b_ref.get_number();
else if(b_ref_type==vm_string)
b_num=trans_string_to_number(b_ref.get_string());
int new_value_address=nasal_vm.gc_alloc(vm_number);
nasal_vm.gc_get(new_value_address).set_number(a_num-b_num);
return new_value_address;
}
int nasal_runtime::nasal_scalar_mult(int a_scalar_addr,int b_scalar_addr)
{
if(a_scalar_addr<0 || b_scalar_addr<0)
{
std::cout<<">> [vm] scalar_mult: memory returned an invalid address.\n";
return -1;
}
nasal_scalar& a_ref=nasal_vm.gc_get(a_scalar_addr);
nasal_scalar& b_ref=nasal_vm.gc_get(b_scalar_addr);
int a_ref_type=a_ref.get_type();
int b_ref_type=b_ref.get_type();
double a_num=(1/0.0)+(-1/0.0);
double b_num=(1/0.0)+(-1/0.0);
if(a_ref_type==vm_number)
a_num=a_ref.get_number();
else if(a_ref_type==vm_string)
a_num=trans_string_to_number(a_ref.get_string());
if(b_ref_type==vm_number)
b_num=b_ref.get_number();
else if(b_ref_type==vm_string)
b_num=trans_string_to_number(b_ref.get_string());
int new_value_address=nasal_vm.gc_alloc(vm_number);
nasal_vm.gc_get(new_value_address).set_number(a_num*b_num);
return new_value_address;
}
int nasal_runtime::nasal_scalar_div(int a_scalar_addr,int b_scalar_addr)
{
if(a_scalar_addr<0 || b_scalar_addr<0)
{
std::cout<<">> [vm] scalar_div: memory returned an invalid address.\n";
return -1;
}
nasal_scalar& a_ref=nasal_vm.gc_get(a_scalar_addr);
nasal_scalar& b_ref=nasal_vm.gc_get(b_scalar_addr);
int a_ref_type=a_ref.get_type();
int b_ref_type=b_ref.get_type();
double a_num=(1/0.0)+(-1/0.0);
double b_num=(1/0.0)+(-1/0.0);
if(a_ref_type==vm_number)
a_num=a_ref.get_number();
else if(a_ref_type==vm_string)
a_num=trans_string_to_number(a_ref.get_string());
if(b_ref_type==vm_number)
b_num=b_ref.get_number();
else if(b_ref_type==vm_string)
b_num=trans_string_to_number(b_ref.get_string());
int new_value_address=nasal_vm.gc_alloc(vm_number);
nasal_vm.gc_get(new_value_address).set_number(a_num/b_num);
return new_value_address;
}
int nasal_runtime::nasal_scalar_link(int a_scalar_addr,int b_scalar_addr)
{
if(a_scalar_addr<0 || b_scalar_addr<0)
{
std::cout<<">> [vm] scalar_link: memory returned an invalid address.\n";
return -1;
}
nasal_scalar& a_ref=nasal_vm.gc_get(a_scalar_addr);
nasal_scalar& b_ref=nasal_vm.gc_get(b_scalar_addr);
int a_ref_type=a_ref.get_type();
int b_ref_type=b_ref.get_type();
if((a_ref_type!=vm_number && a_ref_type!=vm_string)||(b_ref_type!=vm_number && b_ref_type!=vm_string))
{
std::cout<<">> [vm] scalar_link: error value type.\n";
return -1;
}
std::string a_str;
std::string b_str;
a_str=(a_ref_type==vm_number)? trans_number_to_string(a_ref.get_number()):a_ref.get_string();
b_str=(b_ref_type==vm_number)? trans_number_to_string(b_ref.get_number()):b_ref.get_string();
int new_value_address=nasal_vm.gc_alloc(vm_string);
nasal_vm.gc_get(new_value_address).set_string(a_str+b_str);
return new_value_address;
}
int nasal_runtime::nasal_scalar_unary_sub(int a_scalar_addr)
{
if(a_scalar_addr<0)
{
std::cout<<">> [vm] scalar_unary_sub: memory returned an invalid address.\n";
return -1;
}
nasal_scalar& a_ref=nasal_vm.gc_get(a_scalar_addr);
int a_ref_type=a_ref.get_type();
double a_num=(1/0.0)+(-1/0.0);
if(a_ref_type==vm_number)
a_num=a_ref.get_number();
else if(a_ref_type==vm_string)
a_num=trans_string_to_number(a_ref.get_string());
int new_value_address=nasal_vm.gc_alloc(vm_number);
nasal_vm.gc_get(new_value_address).set_number(-a_num);
return new_value_address;
}
int nasal_runtime::nasal_scalar_unary_not(int a_scalar_addr)
{
if(a_scalar_addr<0)
{
std::cout<<">> [vm] scalar_unary_not: memory returned an invalid address.\n";
return -1;
}
nasal_scalar& a_ref=nasal_vm.gc_get(a_scalar_addr);
int a_ref_type=a_ref.get_type();
int new_value_address=-1;
if(a_ref_type==vm_nil)
{
new_value_address=nasal_vm.gc_alloc(vm_number);
nasal_vm.gc_get(new_value_address).set_number(1);
}
else if(a_ref_type==vm_number)
{
double number=(a_ref.get_number()==0);
new_value_address=nasal_vm.gc_alloc(vm_number);
nasal_vm.gc_get(new_value_address).set_number(number);
}
else if(a_ref_type==vm_string)
{
double number=trans_string_to_number(a_ref.get_string());
if(std::isnan(number))
{
new_value_address=nasal_vm.gc_alloc(vm_number);
nasal_vm.gc_get(new_value_address).set_number(!(a_ref.get_string()).length());
}
else
{
new_value_address=nasal_vm.gc_alloc(vm_number);
nasal_vm.gc_get(new_value_address).set_number((double)(number==0));
}
}
else
std::cout<<">> [vm] scalar_unary_not: error value type.\n";
return new_value_address;
}
int nasal_runtime::nasal_scalar_cmp_equal(int a_scalar_addr,int b_scalar_addr)
{
if(a_scalar_addr<0 || b_scalar_addr<0)
{
std::cout<<">> [vm] scalar_cmp_equal: memory returned an invalid address.\n";
return -1;
}
if(a_scalar_addr==b_scalar_addr)
{
int new_value_address=nasal_vm.gc_alloc(vm_number);
nasal_vm.gc_get(new_value_address).set_number(1);
return new_value_address;
}
nasal_scalar& a_ref=nasal_vm.gc_get(a_scalar_addr);
nasal_scalar& b_ref=nasal_vm.gc_get(b_scalar_addr);
int a_ref_type=a_ref.get_type();
int b_ref_type=b_ref.get_type();
if(a_ref_type==vm_nil && b_ref_type==vm_nil)
{
int new_value_address=nasal_vm.gc_alloc(vm_number);
nasal_vm.gc_get(new_value_address).set_number(1);
return new_value_address;
}
else if((a_ref_type==vm_number || a_ref_type==vm_string) && (b_ref_type==vm_number || b_ref_type==vm_string))
{
if(a_ref_type==vm_string && b_ref_type==vm_string)
{
std::string astr=a_ref.get_string();
std::string bstr=b_ref.get_string();
int new_value_address=nasal_vm.gc_alloc(vm_number);
nasal_vm.gc_get(new_value_address).set_number((double)(astr==bstr));
return new_value_address;
}
double a_num;
double b_num;
if(a_ref_type==vm_number)
a_num=a_ref.get_number();
else
a_num=trans_string_to_number(a_ref.get_string());
if(b_ref_type==vm_number)
b_num=b_ref.get_number();
else
b_num=trans_string_to_number(b_ref.get_string());
int new_value_address=nasal_vm.gc_alloc(vm_number);
nasal_vm.gc_get(new_value_address).set_number((double)(a_num==b_num));
return new_value_address;
}
else
{
int new_value_address=nasal_vm.gc_alloc(vm_number);
nasal_vm.gc_get(new_value_address).set_number(0);
return new_value_address;
}
return -1;
}
int nasal_runtime::nasal_scalar_cmp_not_equal(int a_scalar_addr,int b_scalar_addr)
{
if(a_scalar_addr<0 || b_scalar_addr<0)
{
std::cout<<">> [vm] scalar_cmp_not_equal: memory returned an invalid address.\n";
return -1;
}
if(a_scalar_addr==b_scalar_addr)
{
int new_value_address=nasal_vm.gc_alloc(vm_number);
nasal_vm.gc_get(new_value_address).set_number(0);
return new_value_address;
}
nasal_scalar& a_ref=nasal_vm.gc_get(a_scalar_addr);
nasal_scalar& b_ref=nasal_vm.gc_get(b_scalar_addr);
int a_ref_type=a_ref.get_type();
int b_ref_type=b_ref.get_type();
if(a_ref_type==vm_nil && b_ref_type==vm_nil)
{
int new_value_address=nasal_vm.gc_alloc(vm_number);
nasal_vm.gc_get(new_value_address).set_number(0);
return new_value_address;
}
else if((a_ref_type==vm_number || a_ref_type==vm_string) && (b_ref_type==vm_number || b_ref_type==vm_string))
{
if(a_ref_type==vm_string && b_ref_type==vm_string)
{
std::string astr=a_ref.get_string();
std::string bstr=b_ref.get_string();
int new_value_address=nasal_vm.gc_alloc(vm_number);
nasal_vm.gc_get(new_value_address).set_number((double)(astr!=bstr));
return new_value_address;
}
double a_num;
double b_num;
if(a_ref_type==vm_number)
a_num=a_ref.get_number();
else
a_num=trans_string_to_number(a_ref.get_string());
if(b_ref_type==vm_number)
b_num=b_ref.get_number();
else
b_num=trans_string_to_number(b_ref.get_string());
int new_value_address=nasal_vm.gc_alloc(vm_number);
nasal_vm.gc_get(new_value_address).set_number((double)(a_num!=b_num));
return new_value_address;
}
else
{
int new_value_address=nasal_vm.gc_alloc(vm_number);
nasal_vm.gc_get(new_value_address).set_number(1);
return new_value_address;
}
return -1;
}
int nasal_runtime::nasal_scalar_cmp_less(int a_scalar_addr,int b_scalar_addr)
{
if(a_scalar_addr<0 || b_scalar_addr<0)
{
std::cout<<">> [vm] scalar_cmp_less: memory returned an invalid address.\n";
return -1;
}
nasal_scalar& a_ref=nasal_vm.gc_get(a_scalar_addr);
nasal_scalar& b_ref=nasal_vm.gc_get(b_scalar_addr);
int a_ref_type=a_ref.get_type();
int b_ref_type=b_ref.get_type();
if(a_ref_type==vm_string && b_ref_type==vm_string)
{
std::string a_str=a_ref.get_string();
std::string b_str=b_ref.get_string();
int new_value_address=nasal_vm.gc_alloc(vm_number);
nasal_vm.gc_get(new_value_address).set_number((double)(a_str<b_str));
return new_value_address;
}
double a_num=(1/0.0)+(-1/0.0);
double b_num=(1/0.0)+(-1/0.0);
if(a_ref_type==vm_number)
a_num=a_ref.get_number();
else if(a_ref_type==vm_string)
a_num=trans_string_to_number(a_ref.get_string());
if(b_ref_type==vm_number)
b_num=b_ref.get_number();
else if(b_ref_type==vm_string)
b_num=trans_string_to_number(b_ref.get_string());
int new_value_address=nasal_vm.gc_alloc(vm_number);
nasal_vm.gc_get(new_value_address).set_number((double)(a_num<b_num));
return new_value_address;
}
int nasal_runtime::nasal_scalar_cmp_greater(int a_scalar_addr,int b_scalar_addr)
{
if(a_scalar_addr<0 || b_scalar_addr<0)
{
std::cout<<">> [vm] scalar_cmp_greater: memory returned an invalid address.\n";
return -1;
}
nasal_scalar& a_ref=nasal_vm.gc_get(a_scalar_addr);
nasal_scalar& b_ref=nasal_vm.gc_get(b_scalar_addr);
int a_ref_type=a_ref.get_type();
int b_ref_type=b_ref.get_type();
if(a_ref_type==vm_string && b_ref_type==vm_string)
{
std::string a_str=a_ref.get_string();
std::string b_str=b_ref.get_string();
int new_value_address=nasal_vm.gc_alloc(vm_number);
nasal_vm.gc_get(new_value_address).set_number((double)(a_str>b_str));
return new_value_address;
}
double a_num=(1/0.0)+(-1/0.0);
double b_num=(1/0.0)+(-1/0.0);
if(a_ref_type==vm_number)
a_num=a_ref.get_number();
else if(a_ref_type==vm_string)
a_num=trans_string_to_number(a_ref.get_string());
if(b_ref_type==vm_number)
b_num=b_ref.get_number();
else if(b_ref_type==vm_string)
b_num=trans_string_to_number(b_ref.get_string());
int new_value_address=nasal_vm.gc_alloc(vm_number);
nasal_vm.gc_get(new_value_address).set_number((double)(a_num>b_num));
return new_value_address;
}
int nasal_runtime::nasal_scalar_cmp_less_or_equal(int a_scalar_addr,int b_scalar_addr)
{
if(a_scalar_addr<0 || b_scalar_addr<0)
{
std::cout<<">> [vm] scalar_cmp_lequal: memory returned an invalid address.\n";
return -1;
}
nasal_scalar& a_ref=nasal_vm.gc_get(a_scalar_addr);
nasal_scalar& b_ref=nasal_vm.gc_get(b_scalar_addr);
int a_ref_type=a_ref.get_type();
int b_ref_type=b_ref.get_type();
if(a_ref_type==vm_string && b_ref_type==vm_string)
{
std::string a_str=a_ref.get_string();
std::string b_str=b_ref.get_string();
int new_value_address=nasal_vm.gc_alloc(vm_number);
nasal_vm.gc_get(new_value_address).set_number((double)(a_str<=b_str));
return new_value_address;
}
double a_num=(1/0.0)+(-1/0.0);
double b_num=(1/0.0)+(-1/0.0);
if(a_ref_type==vm_number)
a_num=a_ref.get_number();
else if(a_ref_type==vm_string)
a_num=trans_string_to_number(a_ref.get_string());
if(b_ref_type==vm_number)
b_num=b_ref.get_number();
else if(b_ref_type==vm_string)
b_num=trans_string_to_number(b_ref.get_string());
int new_value_address=nasal_vm.gc_alloc(vm_number);
nasal_vm.gc_get(new_value_address).set_number((double)(a_num<=b_num));
return new_value_address;
}
int nasal_runtime::nasal_scalar_cmp_greater_or_equal(int a_scalar_addr,int b_scalar_addr)
{
if(a_scalar_addr<0 || b_scalar_addr<0)
{
std::cout<<">> [vm] scalar_cmp_gequal: memory returned an invalid address.\n";
return -1;
}
nasal_scalar& a_ref=nasal_vm.gc_get(a_scalar_addr);
nasal_scalar& b_ref=nasal_vm.gc_get(b_scalar_addr);
int a_ref_type=a_ref.get_type();
int b_ref_type=b_ref.get_type();
if(a_ref_type==vm_string && b_ref_type==vm_string)
{
std::string a_str=a_ref.get_string();
std::string b_str=b_ref.get_string();
int new_value_address=nasal_vm.gc_alloc(vm_number);
nasal_vm.gc_get(new_value_address).set_number((double)(a_str>=b_str));
return new_value_address;
}
double a_num=(1/0.0)+(-1/0.0);
double b_num=(1/0.0)+(-1/0.0);
if(a_ref_type==vm_number)
a_num=a_ref.get_number();
else if(a_ref_type==vm_string)
a_num=trans_string_to_number(a_ref.get_string());
if(b_ref_type==vm_number)
b_num=b_ref.get_number();
else if(b_ref_type==vm_string)
b_num=trans_string_to_number(b_ref.get_string());
int new_value_address=nasal_vm.gc_alloc(vm_number);
nasal_vm.gc_get(new_value_address).set_number((double)(a_num>=b_num));
return new_value_address;
}
int nasal_runtime::calculation(nasal_ast& node,int local_scope_addr) int nasal_runtime::calculation(nasal_ast& node,int local_scope_addr)
{ {
// after this process, a new address(in nasal_vm.garbage_collector_memory) will be returned // after this process, a new address(in nasal_vm.garbage_collector_memory) will be returned
@ -1109,7 +1566,7 @@ int nasal_runtime::calculation(nasal_ast& node,int local_scope_addr)
{ {
int left_gc_addr=calculation(node.get_children()[0],local_scope_addr); int left_gc_addr=calculation(node.get_children()[0],local_scope_addr);
int right_gc_addr=calculation(node.get_children()[1],local_scope_addr); int right_gc_addr=calculation(node.get_children()[1],local_scope_addr);
ret_address=nasal_scalar_calculator.nasal_scalar_add(left_gc_addr,right_gc_addr); ret_address=nasal_scalar_add(left_gc_addr,right_gc_addr);
// delete the reference of temporary values // delete the reference of temporary values
nasal_vm.del_reference(left_gc_addr); nasal_vm.del_reference(left_gc_addr);
nasal_vm.del_reference(right_gc_addr); nasal_vm.del_reference(right_gc_addr);
@ -1118,7 +1575,7 @@ int nasal_runtime::calculation(nasal_ast& node,int local_scope_addr)
{ {
int left_gc_addr=calculation(node.get_children()[0],local_scope_addr); int left_gc_addr=calculation(node.get_children()[0],local_scope_addr);
int right_gc_addr=calculation(node.get_children()[1],local_scope_addr); int right_gc_addr=calculation(node.get_children()[1],local_scope_addr);
ret_address=nasal_scalar_calculator.nasal_scalar_sub(left_gc_addr,right_gc_addr); ret_address=nasal_scalar_sub(left_gc_addr,right_gc_addr);
// delete the reference of temporary values // delete the reference of temporary values
nasal_vm.del_reference(left_gc_addr); nasal_vm.del_reference(left_gc_addr);
nasal_vm.del_reference(right_gc_addr); nasal_vm.del_reference(right_gc_addr);
@ -1127,7 +1584,7 @@ int nasal_runtime::calculation(nasal_ast& node,int local_scope_addr)
{ {
int left_gc_addr=calculation(node.get_children()[0],local_scope_addr); int left_gc_addr=calculation(node.get_children()[0],local_scope_addr);
int right_gc_addr=calculation(node.get_children()[1],local_scope_addr); int right_gc_addr=calculation(node.get_children()[1],local_scope_addr);
ret_address=nasal_scalar_calculator.nasal_scalar_mult(left_gc_addr,right_gc_addr); ret_address=nasal_scalar_mult(left_gc_addr,right_gc_addr);
// delete the reference of temporary values // delete the reference of temporary values
nasal_vm.del_reference(left_gc_addr); nasal_vm.del_reference(left_gc_addr);
nasal_vm.del_reference(right_gc_addr); nasal_vm.del_reference(right_gc_addr);
@ -1136,7 +1593,7 @@ int nasal_runtime::calculation(nasal_ast& node,int local_scope_addr)
{ {
int left_gc_addr=calculation(node.get_children()[0],local_scope_addr); int left_gc_addr=calculation(node.get_children()[0],local_scope_addr);
int right_gc_addr=calculation(node.get_children()[1],local_scope_addr); int right_gc_addr=calculation(node.get_children()[1],local_scope_addr);
ret_address=nasal_scalar_calculator.nasal_scalar_div(left_gc_addr,right_gc_addr); ret_address=nasal_scalar_div(left_gc_addr,right_gc_addr);
// delete the reference of temporary values // delete the reference of temporary values
nasal_vm.del_reference(left_gc_addr); nasal_vm.del_reference(left_gc_addr);
nasal_vm.del_reference(right_gc_addr); nasal_vm.del_reference(right_gc_addr);
@ -1145,7 +1602,7 @@ int nasal_runtime::calculation(nasal_ast& node,int local_scope_addr)
{ {
int left_gc_addr=calculation(node.get_children()[0],local_scope_addr); int left_gc_addr=calculation(node.get_children()[0],local_scope_addr);
int right_gc_addr=calculation(node.get_children()[1],local_scope_addr); int right_gc_addr=calculation(node.get_children()[1],local_scope_addr);
ret_address=nasal_scalar_calculator.nasal_scalar_link(left_gc_addr,right_gc_addr); ret_address=nasal_scalar_link(left_gc_addr,right_gc_addr);
// delete the reference of temporary values // delete the reference of temporary values
nasal_vm.del_reference(left_gc_addr); nasal_vm.del_reference(left_gc_addr);
nasal_vm.del_reference(right_gc_addr); nasal_vm.del_reference(right_gc_addr);
@ -1154,7 +1611,7 @@ int nasal_runtime::calculation(nasal_ast& node,int local_scope_addr)
{ {
int left_gc_addr=calculation(node.get_children()[0],local_scope_addr); int left_gc_addr=calculation(node.get_children()[0],local_scope_addr);
int right_gc_addr=calculation(node.get_children()[1],local_scope_addr); int right_gc_addr=calculation(node.get_children()[1],local_scope_addr);
ret_address=nasal_scalar_calculator.nasal_scalar_cmp_equal(left_gc_addr,right_gc_addr); ret_address=nasal_scalar_cmp_equal(left_gc_addr,right_gc_addr);
// delete the reference of temporary values // delete the reference of temporary values
nasal_vm.del_reference(left_gc_addr); nasal_vm.del_reference(left_gc_addr);
nasal_vm.del_reference(right_gc_addr); nasal_vm.del_reference(right_gc_addr);
@ -1163,7 +1620,7 @@ int nasal_runtime::calculation(nasal_ast& node,int local_scope_addr)
{ {
int left_gc_addr=calculation(node.get_children()[0],local_scope_addr); int left_gc_addr=calculation(node.get_children()[0],local_scope_addr);
int right_gc_addr=calculation(node.get_children()[1],local_scope_addr); int right_gc_addr=calculation(node.get_children()[1],local_scope_addr);
ret_address=nasal_scalar_calculator.nasal_scalar_cmp_not_equal(left_gc_addr,right_gc_addr); ret_address=nasal_scalar_cmp_not_equal(left_gc_addr,right_gc_addr);
// delete the reference of temporary values // delete the reference of temporary values
nasal_vm.del_reference(left_gc_addr); nasal_vm.del_reference(left_gc_addr);
nasal_vm.del_reference(right_gc_addr); nasal_vm.del_reference(right_gc_addr);
@ -1172,7 +1629,7 @@ int nasal_runtime::calculation(nasal_ast& node,int local_scope_addr)
{ {
int left_gc_addr=calculation(node.get_children()[0],local_scope_addr); int left_gc_addr=calculation(node.get_children()[0],local_scope_addr);
int right_gc_addr=calculation(node.get_children()[1],local_scope_addr); int right_gc_addr=calculation(node.get_children()[1],local_scope_addr);
ret_address=nasal_scalar_calculator.nasal_scalar_cmp_less(left_gc_addr,right_gc_addr); ret_address=nasal_scalar_cmp_less(left_gc_addr,right_gc_addr);
// delete the reference of temporary values // delete the reference of temporary values
nasal_vm.del_reference(left_gc_addr); nasal_vm.del_reference(left_gc_addr);
nasal_vm.del_reference(right_gc_addr); nasal_vm.del_reference(right_gc_addr);
@ -1181,7 +1638,7 @@ int nasal_runtime::calculation(nasal_ast& node,int local_scope_addr)
{ {
int left_gc_addr=calculation(node.get_children()[0],local_scope_addr); int left_gc_addr=calculation(node.get_children()[0],local_scope_addr);
int right_gc_addr=calculation(node.get_children()[1],local_scope_addr); int right_gc_addr=calculation(node.get_children()[1],local_scope_addr);
ret_address=nasal_scalar_calculator.nasal_scalar_cmp_less_or_equal(left_gc_addr,right_gc_addr); ret_address=nasal_scalar_cmp_less_or_equal(left_gc_addr,right_gc_addr);
// delete the reference of temporary values // delete the reference of temporary values
nasal_vm.del_reference(left_gc_addr); nasal_vm.del_reference(left_gc_addr);
nasal_vm.del_reference(right_gc_addr); nasal_vm.del_reference(right_gc_addr);
@ -1190,7 +1647,7 @@ int nasal_runtime::calculation(nasal_ast& node,int local_scope_addr)
{ {
int left_gc_addr=calculation(node.get_children()[0],local_scope_addr); int left_gc_addr=calculation(node.get_children()[0],local_scope_addr);
int right_gc_addr=calculation(node.get_children()[1],local_scope_addr); int right_gc_addr=calculation(node.get_children()[1],local_scope_addr);
ret_address=nasal_scalar_calculator.nasal_scalar_cmp_greater(left_gc_addr,right_gc_addr); ret_address=nasal_scalar_cmp_greater(left_gc_addr,right_gc_addr);
// delete the reference of temporary values // delete the reference of temporary values
nasal_vm.del_reference(left_gc_addr); nasal_vm.del_reference(left_gc_addr);
nasal_vm.del_reference(right_gc_addr); nasal_vm.del_reference(right_gc_addr);
@ -1199,7 +1656,7 @@ int nasal_runtime::calculation(nasal_ast& node,int local_scope_addr)
{ {
int left_gc_addr=calculation(node.get_children()[0],local_scope_addr); int left_gc_addr=calculation(node.get_children()[0],local_scope_addr);
int right_gc_addr=calculation(node.get_children()[1],local_scope_addr); int right_gc_addr=calculation(node.get_children()[1],local_scope_addr);
ret_address=nasal_scalar_calculator.nasal_scalar_cmp_greater_or_equal(left_gc_addr,right_gc_addr); ret_address=nasal_scalar_cmp_greater_or_equal(left_gc_addr,right_gc_addr);
// delete the reference of temporary values // delete the reference of temporary values
nasal_vm.del_reference(left_gc_addr); nasal_vm.del_reference(left_gc_addr);
nasal_vm.del_reference(right_gc_addr); nasal_vm.del_reference(right_gc_addr);
@ -1255,14 +1712,14 @@ int nasal_runtime::calculation(nasal_ast& node,int local_scope_addr)
else if(calculation_type==ast_unary_not) else if(calculation_type==ast_unary_not)
{ {
int addr=calculation(node.get_children()[0],local_scope_addr); int addr=calculation(node.get_children()[0],local_scope_addr);
ret_address=nasal_scalar_calculator.nasal_scalar_unary_not(addr); ret_address=nasal_scalar_unary_not(addr);
// delete the reference of temporary values // delete the reference of temporary values
nasal_vm.del_reference(addr); nasal_vm.del_reference(addr);
} }
else if(calculation_type==ast_unary_sub) else if(calculation_type==ast_unary_sub)
{ {
int addr=calculation(node.get_children()[0],local_scope_addr); int addr=calculation(node.get_children()[0],local_scope_addr);
ret_address=nasal_scalar_calculator.nasal_scalar_unary_sub(addr); ret_address=nasal_scalar_unary_sub(addr);
// delete the reference of temporary values // delete the reference of temporary values
nasal_vm.del_reference(addr); nasal_vm.del_reference(addr);
} }
@ -1289,7 +1746,7 @@ int nasal_runtime::calculation(nasal_ast& node,int local_scope_addr)
int scalar_mem_space=call_scalar_mem(node.get_children()[0],local_scope_addr); int scalar_mem_space=call_scalar_mem(node.get_children()[0],local_scope_addr);
int scalar_val_space=nasal_vm.mem_get(scalar_mem_space); int scalar_val_space=nasal_vm.mem_get(scalar_mem_space);
int new_scalar_gc_addr=calculation(node.get_children()[1],local_scope_addr); int new_scalar_gc_addr=calculation(node.get_children()[1],local_scope_addr);
int result_val_address=nasal_scalar_calculator.nasal_scalar_add(scalar_val_space,new_scalar_gc_addr); int result_val_address=nasal_scalar_add(scalar_val_space,new_scalar_gc_addr);
nasal_vm.del_reference(new_scalar_gc_addr); nasal_vm.del_reference(new_scalar_gc_addr);
nasal_vm.mem_change(scalar_mem_space,result_val_address);// this progress will delete the reference to old gc_addr in scalar_mem_space nasal_vm.mem_change(scalar_mem_space,result_val_address);// this progress will delete the reference to old gc_addr in scalar_mem_space
nasal_vm.add_reference(result_val_address);// this reference is reserved for ret_address nasal_vm.add_reference(result_val_address);// this reference is reserved for ret_address
@ -1300,7 +1757,7 @@ int nasal_runtime::calculation(nasal_ast& node,int local_scope_addr)
int scalar_mem_space=call_scalar_mem(node.get_children()[0],local_scope_addr); int scalar_mem_space=call_scalar_mem(node.get_children()[0],local_scope_addr);
int scalar_val_space=nasal_vm.mem_get(scalar_mem_space); int scalar_val_space=nasal_vm.mem_get(scalar_mem_space);
int new_scalar_gc_addr=calculation(node.get_children()[1],local_scope_addr); int new_scalar_gc_addr=calculation(node.get_children()[1],local_scope_addr);
int result_val_address=nasal_scalar_calculator.nasal_scalar_sub(scalar_val_space,new_scalar_gc_addr); int result_val_address=nasal_scalar_sub(scalar_val_space,new_scalar_gc_addr);
nasal_vm.del_reference(new_scalar_gc_addr); nasal_vm.del_reference(new_scalar_gc_addr);
nasal_vm.mem_change(scalar_mem_space,result_val_address);// this progress will delete the reference to old gc_addr in scalar_mem_space nasal_vm.mem_change(scalar_mem_space,result_val_address);// this progress will delete the reference to old gc_addr in scalar_mem_space
nasal_vm.add_reference(result_val_address);// this reference is reserved for ret_address nasal_vm.add_reference(result_val_address);// this reference is reserved for ret_address
@ -1311,7 +1768,7 @@ int nasal_runtime::calculation(nasal_ast& node,int local_scope_addr)
int scalar_mem_space=call_scalar_mem(node.get_children()[0],local_scope_addr); int scalar_mem_space=call_scalar_mem(node.get_children()[0],local_scope_addr);
int scalar_val_space=nasal_vm.mem_get(scalar_mem_space); int scalar_val_space=nasal_vm.mem_get(scalar_mem_space);
int new_scalar_gc_addr=calculation(node.get_children()[1],local_scope_addr); int new_scalar_gc_addr=calculation(node.get_children()[1],local_scope_addr);
int result_val_address=nasal_scalar_calculator.nasal_scalar_div(scalar_val_space,new_scalar_gc_addr); int result_val_address=nasal_scalar_div(scalar_val_space,new_scalar_gc_addr);
nasal_vm.del_reference(new_scalar_gc_addr); nasal_vm.del_reference(new_scalar_gc_addr);
nasal_vm.mem_change(scalar_mem_space,result_val_address);// this progress will delete the reference to old gc_addr in scalar_mem_space nasal_vm.mem_change(scalar_mem_space,result_val_address);// this progress will delete the reference to old gc_addr in scalar_mem_space
nasal_vm.add_reference(result_val_address);// this reference is reserved for ret_address nasal_vm.add_reference(result_val_address);// this reference is reserved for ret_address
@ -1322,7 +1779,7 @@ int nasal_runtime::calculation(nasal_ast& node,int local_scope_addr)
int scalar_mem_space=call_scalar_mem(node.get_children()[0],local_scope_addr); int scalar_mem_space=call_scalar_mem(node.get_children()[0],local_scope_addr);
int scalar_val_space=nasal_vm.mem_get(scalar_mem_space); int scalar_val_space=nasal_vm.mem_get(scalar_mem_space);
int new_scalar_gc_addr=calculation(node.get_children()[1],local_scope_addr); int new_scalar_gc_addr=calculation(node.get_children()[1],local_scope_addr);
int result_val_address=nasal_scalar_calculator.nasal_scalar_mult(scalar_val_space,new_scalar_gc_addr); int result_val_address=nasal_scalar_mult(scalar_val_space,new_scalar_gc_addr);
nasal_vm.del_reference(new_scalar_gc_addr); nasal_vm.del_reference(new_scalar_gc_addr);
nasal_vm.mem_change(scalar_mem_space,result_val_address);// this progress will delete the reference to old gc_addr in scalar_mem_space nasal_vm.mem_change(scalar_mem_space,result_val_address);// this progress will delete the reference to old gc_addr in scalar_mem_space
nasal_vm.add_reference(result_val_address);// this reference is reserved for ret_address nasal_vm.add_reference(result_val_address);// this reference is reserved for ret_address
@ -1333,7 +1790,7 @@ int nasal_runtime::calculation(nasal_ast& node,int local_scope_addr)
int scalar_mem_space=call_scalar_mem(node.get_children()[0],local_scope_addr); int scalar_mem_space=call_scalar_mem(node.get_children()[0],local_scope_addr);
int scalar_val_space=nasal_vm.mem_get(scalar_mem_space); int scalar_val_space=nasal_vm.mem_get(scalar_mem_space);
int new_scalar_gc_addr=calculation(node.get_children()[1],local_scope_addr); int new_scalar_gc_addr=calculation(node.get_children()[1],local_scope_addr);
int result_val_address=nasal_scalar_calculator.nasal_scalar_link(scalar_val_space,new_scalar_gc_addr); int result_val_address=nasal_scalar_link(scalar_val_space,new_scalar_gc_addr);
nasal_vm.del_reference(new_scalar_gc_addr); nasal_vm.del_reference(new_scalar_gc_addr);
nasal_vm.mem_change(scalar_mem_space,result_val_address);// this progress will delete the reference to old gc_addr in scalar_mem_space nasal_vm.mem_change(scalar_mem_space,result_val_address);// this progress will delete the reference to old gc_addr in scalar_mem_space
nasal_vm.add_reference(result_val_address);// this reference is reserved for ret_address nasal_vm.add_reference(result_val_address);// this reference is reserved for ret_address