update
This commit is contained in:
parent
e9fd953273
commit
f811368491
2
nasal.h
2
nasal.h
|
@ -26,7 +26,7 @@
|
||||||
#include "nasal_import.h"
|
#include "nasal_import.h"
|
||||||
#include "nasal_codegen.h"
|
#include "nasal_codegen.h"
|
||||||
#include "nasal_gc.h"
|
#include "nasal_gc.h"
|
||||||
#include "nasal_runtime.h"
|
|
||||||
#include "nasal_builtin.h"
|
#include "nasal_builtin.h"
|
||||||
|
#include "nasal_runtime.h"
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
226
nasal_builtin.h
226
nasal_builtin.h
|
@ -1,17 +1,115 @@
|
||||||
#ifndef __NASAL_BUILTIN_H__
|
#ifndef __NASAL_BUILTIN_H__
|
||||||
#define __NASAL_BUILTIN_H__
|
#define __NASAL_BUILTIN_H__
|
||||||
|
|
||||||
|
// builtin functions must be called inside a outer function like this:
|
||||||
|
// var print=func(elements...)
|
||||||
|
// {
|
||||||
|
// nasal_call_builtin_std_cout(elements);
|
||||||
|
// return nil;
|
||||||
|
// }
|
||||||
|
// builtin function nasal_call_builtin_std_cout is wrapped up by print
|
||||||
|
|
||||||
|
// used to find values that builtin function uses
|
||||||
#define in_builtin_find(value_name_string) (local_scope_addr>=0?nasal_vm.gc_get(local_scope_addr).get_closure().get_value_address(value_name_string):-1)
|
#define in_builtin_find(value_name_string) (local_scope_addr>=0?nasal_vm.gc_get(local_scope_addr).get_closure().get_value_address(value_name_string):-1)
|
||||||
|
// used to check found value's type
|
||||||
|
// types are:vm_nil vm_number vm_string vm_vector vm_hash vm_function
|
||||||
|
// dynamic values will be generated as vector by the outer function
|
||||||
#define in_builtin_check(value_addr,value_type) (nasal_vm.gc_get(value_addr).get_type()==(value_type))
|
#define in_builtin_check(value_addr,value_type) (nasal_vm.gc_get(value_addr).get_type()==(value_type))
|
||||||
|
|
||||||
int nasal_runtime::builtin_print(int local_scope_addr)
|
// declaration of builtin functions
|
||||||
|
// to add new builtin function,declare it here and write the definition below
|
||||||
|
int builtin_print(int);
|
||||||
|
int builtin_append(int);
|
||||||
|
int builtin_setsize(int);
|
||||||
|
int builtin_system(int);
|
||||||
|
int builtin_input(int);
|
||||||
|
int builtin_sleep(int);
|
||||||
|
int builtin_finput(int);
|
||||||
|
int builtin_foutput(int);
|
||||||
|
int builtin_split(int);
|
||||||
|
int builtin_rand(int);
|
||||||
|
int builtin_id(int);
|
||||||
|
int builtin_int(int);
|
||||||
|
int builtin_num(int);
|
||||||
|
int builtin_pop(int);
|
||||||
|
int builtin_str(int);
|
||||||
|
int builtin_size(int);
|
||||||
|
int builtin_xor(int);
|
||||||
|
int builtin_and(int);
|
||||||
|
int builtin_or(int);
|
||||||
|
int builtin_nand(int);
|
||||||
|
int builtin_not(int);
|
||||||
|
int builtin_sin(int);
|
||||||
|
int builtin_cos(int);
|
||||||
|
int builtin_tan(int);
|
||||||
|
int builtin_exp(int);
|
||||||
|
int builtin_ln(int);
|
||||||
|
int builtin_sqrt(int);
|
||||||
|
int builtin_atan2(int);
|
||||||
|
int builtin_time(int);
|
||||||
|
int builtin_contains(int);
|
||||||
|
int builtin_delete(int);
|
||||||
|
int builtin_getkeys(int);
|
||||||
|
int builtin_import(int);
|
||||||
|
int builtin_die_state;
|
||||||
|
int builtin_die(int);
|
||||||
|
int builtin_type(int);
|
||||||
|
int builtin_substr(int);
|
||||||
|
|
||||||
|
// register builtin function's name and it's address here in this table below
|
||||||
|
// this table must and with {"",NULL}
|
||||||
|
struct FUNC_TABLE
|
||||||
|
{
|
||||||
|
std::string func_name;
|
||||||
|
int (*func_pointer)(int x);
|
||||||
|
} builtin_func_table[]=
|
||||||
|
{
|
||||||
|
{"nasal_call_builtin_std_cout", builtin_print},
|
||||||
|
{"nasal_call_builtin_push_back", builtin_append},
|
||||||
|
{"nasal_call_builtin_set_size", builtin_setsize},
|
||||||
|
{"nasal_call_builtin_system", builtin_system},
|
||||||
|
{"nasal_call_builtin_input", builtin_input},
|
||||||
|
{"nasal_call_builtin_sleep", builtin_sleep},
|
||||||
|
{"nasal_call_builtin_finput", builtin_finput},
|
||||||
|
{"nasal_call_builtin_foutput", builtin_foutput},
|
||||||
|
{"nasal_call_builtin_split", builtin_split},
|
||||||
|
{"nasal_call_builtin_rand", builtin_rand},
|
||||||
|
{"nasal_call_builtin_get_id", builtin_id},
|
||||||
|
{"nasal_call_builtin_trans_int", builtin_int},
|
||||||
|
{"nasal_call_builtin_trans_num", builtin_num},
|
||||||
|
{"nasal_call_builtin_pop_back", builtin_pop},
|
||||||
|
{"nasal_call_builtin_trans_str", builtin_str},
|
||||||
|
{"nasal_call_builtin_size", builtin_size},
|
||||||
|
{"nasal_call_builtin_xor", builtin_xor},
|
||||||
|
{"nasal_call_builtin_and", builtin_and},
|
||||||
|
{"nasal_call_builtin_or", builtin_or},
|
||||||
|
{"nasal_call_builtin_nand", builtin_nand},
|
||||||
|
{"nasal_call_builtin_not", builtin_not},
|
||||||
|
{"nasal_call_builtin_sin", builtin_sin},
|
||||||
|
{"nasal_call_builtin_cos", builtin_cos},
|
||||||
|
{"nasal_call_builtin_tan", builtin_tan},
|
||||||
|
{"nasal_call_builtin_exp", builtin_exp},
|
||||||
|
{"nasal_call_builtin_cpp_math_ln", builtin_ln},
|
||||||
|
{"nasal_call_builtin_cpp_math_sqrt", builtin_sqrt},
|
||||||
|
{"nasal_call_builtin_cpp_atan2", builtin_atan2},
|
||||||
|
{"nasal_call_builtin_time", builtin_time},
|
||||||
|
{"nasal_call_builtin_contains", builtin_contains},
|
||||||
|
{"nasal_call_builtin_delete", builtin_delete},
|
||||||
|
{"nasal_call_builtin_get_keys", builtin_getkeys},
|
||||||
|
{"nasal_call_import", builtin_import},
|
||||||
|
{"nasal_call_builtin_die", builtin_die},
|
||||||
|
{"nasal_call_builtin_type", builtin_type},
|
||||||
|
{"nasal_call_builtin_substr", builtin_substr},
|
||||||
|
{"", NULL}
|
||||||
|
};
|
||||||
|
|
||||||
|
int builtin_print(int local_scope_addr)
|
||||||
{
|
{
|
||||||
// get arguments
|
// get arguments
|
||||||
int vector_value_addr=in_builtin_find("elements");
|
int vector_value_addr=in_builtin_find("elements");
|
||||||
if(vector_value_addr<0 || !in_builtin_check(vector_value_addr,vm_vector))
|
if(vector_value_addr<0 || !in_builtin_check(vector_value_addr,vm_vector))
|
||||||
{
|
{
|
||||||
std::cout<<">> [runtime] builtin_print: \"elements\" has wrong value type(must be vector).\n";
|
std::cout<<">> [runtime] builtin_print: \"elements\" has wrong value type(must be vector).\n";
|
||||||
++error;
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
// main process
|
// main process
|
||||||
|
@ -35,20 +133,18 @@ int nasal_runtime::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 nasal_runtime::builtin_append(int local_scope_addr)
|
int builtin_append(int local_scope_addr)
|
||||||
{
|
{
|
||||||
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");
|
||||||
if(vector_value_addr<0 || !in_builtin_check(vector_value_addr,vm_vector))
|
if(vector_value_addr<0 || !in_builtin_check(vector_value_addr,vm_vector))
|
||||||
{
|
{
|
||||||
std::cout<<">> [runtime] builtin_append: \"vector\" has wrong value type(must be vector).\n";
|
std::cout<<">> [runtime] builtin_append: \"vector\" has wrong value type(must be vector).\n";
|
||||||
++error;
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if(elem_value_addr<0 || !in_builtin_check(elem_value_addr,vm_vector))
|
if(elem_value_addr<0 || !in_builtin_check(elem_value_addr,vm_vector))
|
||||||
{
|
{
|
||||||
std::cout<<">> [runtime] builtin_append: \"elements\" has wrong value type(must be vector).\n";
|
std::cout<<">> [runtime] builtin_append: \"elements\" has wrong value type(must be vector).\n";
|
||||||
++error;
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
nasal_vector& ref_vector=nasal_vm.gc_get(vector_value_addr).get_vector();
|
nasal_vector& ref_vector=nasal_vm.gc_get(vector_value_addr).get_vector();
|
||||||
|
@ -63,27 +159,24 @@ int nasal_runtime::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 nasal_runtime::builtin_setsize(int local_scope_addr)
|
int builtin_setsize(int local_scope_addr)
|
||||||
{
|
{
|
||||||
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");
|
||||||
if(vector_value_addr<0 || nasal_vm.gc_get(vector_value_addr).get_type()!=vm_vector)
|
if(vector_value_addr<0 || nasal_vm.gc_get(vector_value_addr).get_type()!=vm_vector)
|
||||||
{
|
{
|
||||||
std::cout<<">> [runtime] builtin_setsize: \"vector\" has wrong value type(must be vector).\n";
|
std::cout<<">> [runtime] builtin_setsize: \"vector\" has wrong value type(must be vector).\n";
|
||||||
++error;
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if(size_value_addr<0)
|
if(size_value_addr<0)
|
||||||
{
|
{
|
||||||
std::cout<<">> [runtime] builtin_setsize: \"size\" has wrong value type(must be string or number).\n";
|
std::cout<<">> [runtime] builtin_setsize: \"size\" has wrong value type(must be string or number).\n";
|
||||||
++error;
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
int type=nasal_vm.gc_get(size_value_addr).get_type();
|
int type=nasal_vm.gc_get(size_value_addr).get_type();
|
||||||
if(type!=vm_number && type!=vm_string)
|
if(type!=vm_number && type!=vm_string)
|
||||||
{
|
{
|
||||||
std::cout<<">> [runtime] builtin_setsize: size is not a number.\n";
|
std::cout<<">> [runtime] builtin_setsize: size is not a number.\n";
|
||||||
++error;
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
int number;
|
int number;
|
||||||
|
@ -96,7 +189,6 @@ int nasal_runtime::builtin_setsize(int local_scope_addr)
|
||||||
if(std::isnan(tmp))
|
if(std::isnan(tmp))
|
||||||
{
|
{
|
||||||
std::cout<<">> [runtime] builtin_setsize: size is not a numerable string.\n";
|
std::cout<<">> [runtime] builtin_setsize: size is not a numerable string.\n";
|
||||||
++error;
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
number=(int)tmp;
|
number=(int)tmp;
|
||||||
|
@ -104,7 +196,6 @@ int nasal_runtime::builtin_setsize(int local_scope_addr)
|
||||||
if(number<0)
|
if(number<0)
|
||||||
{
|
{
|
||||||
std::cout<<">> [runtime] builtin_setsize: size must be greater than -1.\n";
|
std::cout<<">> [runtime] builtin_setsize: size must be greater than -1.\n";
|
||||||
++error;
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
nasal_vector& ref_vector=nasal_vm.gc_get(vector_value_addr).get_vector();
|
nasal_vector& ref_vector=nasal_vm.gc_get(vector_value_addr).get_vector();
|
||||||
|
@ -126,13 +217,12 @@ int nasal_runtime::builtin_setsize(int local_scope_addr)
|
||||||
return ret_addr;
|
return ret_addr;
|
||||||
}
|
}
|
||||||
|
|
||||||
int nasal_runtime::builtin_system(int local_scope_addr)
|
int builtin_system(int local_scope_addr)
|
||||||
{
|
{
|
||||||
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)
|
||||||
{
|
{
|
||||||
std::cout<<">> [runtime] builtin_system: \"str\" has wrong value type(must be string).\n";
|
std::cout<<">> [runtime] builtin_system: \"str\" has wrong value type(must be string).\n";
|
||||||
++error;
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
std::string str=nasal_vm.gc_get(str_value_addr).get_string();
|
std::string str=nasal_vm.gc_get(str_value_addr).get_string();
|
||||||
|
@ -147,7 +237,7 @@ int nasal_runtime::builtin_system(int local_scope_addr)
|
||||||
return ret_addr;
|
return ret_addr;
|
||||||
}
|
}
|
||||||
|
|
||||||
int nasal_runtime::builtin_input(int local_scope_addr)
|
int builtin_input(int local_scope_addr)
|
||||||
{
|
{
|
||||||
int ret_addr=nasal_vm.gc_alloc(vm_string);
|
int ret_addr=nasal_vm.gc_alloc(vm_string);
|
||||||
std::string str;
|
std::string str;
|
||||||
|
@ -156,13 +246,12 @@ int nasal_runtime::builtin_input(int local_scope_addr)
|
||||||
return ret_addr;
|
return ret_addr;
|
||||||
}
|
}
|
||||||
|
|
||||||
int nasal_runtime::builtin_sleep(int local_scope_addr)
|
int builtin_sleep(int local_scope_addr)
|
||||||
{
|
{
|
||||||
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))
|
||||||
{
|
{
|
||||||
std::cout<<">> [runtime] builtin_sleep: \"duration\" has wrong value type(must be string or number).\n";
|
std::cout<<">> [runtime] builtin_sleep: \"duration\" has wrong value type(must be string or number).\n";
|
||||||
++error;
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
unsigned long sleep_time=0;
|
unsigned long sleep_time=0;
|
||||||
|
@ -173,7 +262,6 @@ int nasal_runtime::builtin_sleep(int local_scope_addr)
|
||||||
if(std::isnan(number))
|
if(std::isnan(number))
|
||||||
{
|
{
|
||||||
std::cout<<">> [runtime] builtin_sleep: this is not a numerable string.\n";
|
std::cout<<">> [runtime] builtin_sleep: this is not a numerable string.\n";
|
||||||
++error;
|
|
||||||
return -1;
|
return -1;
|
||||||
}sleep_time=(unsigned long)number;
|
}sleep_time=(unsigned long)number;
|
||||||
}
|
}
|
||||||
|
@ -184,13 +272,12 @@ int nasal_runtime::builtin_sleep(int local_scope_addr)
|
||||||
return ret_addr;
|
return ret_addr;
|
||||||
}
|
}
|
||||||
|
|
||||||
int nasal_runtime::builtin_finput(int local_scope_addr)
|
int builtin_finput(int local_scope_addr)
|
||||||
{
|
{
|
||||||
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)
|
||||||
{
|
{
|
||||||
std::cout<<">> [runtime] builtin_finput: \"filename\" has wrong value type(must be string).\n";
|
std::cout<<">> [runtime] builtin_finput: \"filename\" has wrong value type(must be string).\n";
|
||||||
++error;
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
std::string filename=nasal_vm.gc_get(value_addr).get_string();
|
std::string filename=nasal_vm.gc_get(value_addr).get_string();
|
||||||
|
@ -212,20 +299,18 @@ int nasal_runtime::builtin_finput(int local_scope_addr)
|
||||||
return ret_addr;
|
return ret_addr;
|
||||||
}
|
}
|
||||||
|
|
||||||
int nasal_runtime::builtin_foutput(int local_scope_addr)
|
int builtin_foutput(int local_scope_addr)
|
||||||
{
|
{
|
||||||
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");
|
||||||
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)
|
||||||
{
|
{
|
||||||
std::cout<<">> [runtime] builtin_foutput: \"filename\" has wrong value type(must be string).\n";
|
std::cout<<">> [runtime] builtin_foutput: \"filename\" has wrong value type(must be string).\n";
|
||||||
++error;
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
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)
|
||||||
{
|
{
|
||||||
std::cout<<">> [runtime] builtin_foutput: \"str\" has wrong value type(must be string).\n";
|
std::cout<<">> [runtime] builtin_foutput: \"str\" has wrong value type(must be string).\n";
|
||||||
++error;
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
std::string filename=nasal_vm.gc_get(value_addr).get_string();
|
std::string filename=nasal_vm.gc_get(value_addr).get_string();
|
||||||
|
@ -237,20 +322,18 @@ int nasal_runtime::builtin_foutput(int local_scope_addr)
|
||||||
return ret_addr;
|
return ret_addr;
|
||||||
}
|
}
|
||||||
|
|
||||||
int nasal_runtime::builtin_split(int local_scope_addr)
|
int builtin_split(int local_scope_addr)
|
||||||
{
|
{
|
||||||
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");
|
||||||
if(delimeter_value_addr<0 || nasal_vm.gc_get(delimeter_value_addr).get_type()!=vm_string)
|
if(delimeter_value_addr<0 || nasal_vm.gc_get(delimeter_value_addr).get_type()!=vm_string)
|
||||||
{
|
{
|
||||||
std::cout<<">> [runtime] builtin_split: \"delimeter\" has wrong value type(must be string).\n";
|
std::cout<<">> [runtime] builtin_split: \"delimeter\" has wrong value type(must be string).\n";
|
||||||
++error;
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if(string_value_addr<0 || nasal_vm.gc_get(string_value_addr).get_type()!=vm_string)
|
if(string_value_addr<0 || nasal_vm.gc_get(string_value_addr).get_type()!=vm_string)
|
||||||
{
|
{
|
||||||
std::cout<<">> [runtime] builtin_split: \"string\" has wrong value type(must be string).\n";
|
std::cout<<">> [runtime] builtin_split: \"string\" has wrong value type(must be string).\n";
|
||||||
++error;
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
std::string delimeter=nasal_vm.gc_get(delimeter_value_addr).get_string();
|
std::string delimeter=nasal_vm.gc_get(delimeter_value_addr).get_string();
|
||||||
|
@ -306,13 +389,12 @@ int nasal_runtime::builtin_split(int local_scope_addr)
|
||||||
}
|
}
|
||||||
return ret_addr;
|
return ret_addr;
|
||||||
}
|
}
|
||||||
int nasal_runtime::builtin_rand(int local_scope_addr)
|
int builtin_rand(int local_scope_addr)
|
||||||
{
|
{
|
||||||
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))
|
||||||
{
|
{
|
||||||
std::cout<<">> [runtime] builtin_rand: \"seed\" has wrong value type(must be nil or number).\n";
|
std::cout<<">> [runtime] builtin_rand: \"seed\" has wrong value type(must be nil or number).\n";
|
||||||
++error;
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if(nasal_vm.gc_get(value_addr).get_type()==vm_number)
|
if(nasal_vm.gc_get(value_addr).get_type()==vm_number)
|
||||||
|
@ -329,26 +411,24 @@ int nasal_runtime::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 nasal_runtime::builtin_id(int local_scope_addr)
|
int builtin_id(int local_scope_addr)
|
||||||
{
|
{
|
||||||
int value_addr=in_builtin_find("thing");
|
int value_addr=in_builtin_find("thing");
|
||||||
if(value_addr<0)
|
if(value_addr<0)
|
||||||
{
|
{
|
||||||
std::cout<<">> [runtime] builtin_id: cannot find \"thing\".\n";
|
std::cout<<">> [runtime] builtin_id: cannot find \"thing\".\n";
|
||||||
++error;
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
int ret_addr=nasal_vm.gc_alloc(vm_number);
|
int ret_addr=nasal_vm.gc_alloc(vm_number);
|
||||||
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 nasal_runtime::builtin_int(int local_scope_addr)
|
int builtin_int(int local_scope_addr)
|
||||||
{
|
{
|
||||||
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)
|
||||||
{
|
{
|
||||||
std::cout<<">> [runtime] builtin_int: \"value\" has wrong value type(must be number).\n";
|
std::cout<<">> [runtime] builtin_int: \"value\" has wrong value type(must be number).\n";
|
||||||
++error;
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
int number=(int)nasal_vm.gc_get(value_addr).get_number();
|
int number=(int)nasal_vm.gc_get(value_addr).get_number();
|
||||||
|
@ -356,13 +436,12 @@ int nasal_runtime::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 nasal_runtime::builtin_num(int local_scope_addr)
|
int builtin_num(int local_scope_addr)
|
||||||
{
|
{
|
||||||
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))
|
||||||
{
|
{
|
||||||
std::cout<<">> [runtime] builtin_num: \"value\" has wrong value type(must be string).\n";
|
std::cout<<">> [runtime] builtin_num: \"value\" has wrong value type(must be string).\n";
|
||||||
++error;
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
std::string str=nasal_vm.gc_get(value_addr).get_string();
|
std::string str=nasal_vm.gc_get(value_addr).get_string();
|
||||||
|
@ -370,25 +449,23 @@ int nasal_runtime::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 nasal_runtime::builtin_pop(int local_scope_addr)
|
int builtin_pop(int local_scope_addr)
|
||||||
{
|
{
|
||||||
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)
|
||||||
{
|
{
|
||||||
std::cout<<">> [runtime] builtin_pop: \"vector\" has wrong value type(must be vector).\n";
|
std::cout<<">> [runtime] builtin_pop: \"vector\" has wrong value type(must be vector).\n";
|
||||||
++error;
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
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 nasal_runtime::builtin_str(int local_scope_addr)
|
int builtin_str(int local_scope_addr)
|
||||||
{
|
{
|
||||||
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)
|
||||||
{
|
{
|
||||||
std::cout<<">> [runtime] builtin_str: \"number\" has wrong value type(must be number).\n";
|
std::cout<<">> [runtime] builtin_str: \"number\" has wrong value type(must be number).\n";
|
||||||
++error;
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
double number=nasal_vm.gc_get(value_addr).get_number();
|
double number=nasal_vm.gc_get(value_addr).get_number();
|
||||||
|
@ -396,13 +473,12 @@ int nasal_runtime::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 nasal_runtime::builtin_size(int local_scope_addr)
|
int builtin_size(int local_scope_addr)
|
||||||
{
|
{
|
||||||
int value_addr=in_builtin_find("object");
|
int value_addr=in_builtin_find("object");
|
||||||
if(value_addr<0)
|
if(value_addr<0)
|
||||||
{
|
{
|
||||||
std::cout<<">> [runtime] builtin_size: cannot find value \"object\".\n";
|
std::cout<<">> [runtime] builtin_size: cannot find value \"object\".\n";
|
||||||
++error;
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
int type=nasal_vm.gc_get(value_addr).get_type();
|
int type=nasal_vm.gc_get(value_addr).get_type();
|
||||||
|
@ -427,20 +503,18 @@ int nasal_runtime::builtin_size(int local_scope_addr)
|
||||||
}
|
}
|
||||||
return ret_addr;
|
return ret_addr;
|
||||||
}
|
}
|
||||||
int nasal_runtime::builtin_xor(int local_scope_addr)
|
int builtin_xor(int local_scope_addr)
|
||||||
{
|
{
|
||||||
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");
|
||||||
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)
|
||||||
{
|
{
|
||||||
std::cout<<">> [runtime] builtin_xor: \"a\" has wrong value type(must be number).\n";
|
std::cout<<">> [runtime] builtin_xor: \"a\" has wrong value type(must be number).\n";
|
||||||
++error;
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if(b_addr<0 || nasal_vm.gc_get(b_addr).get_type()!=vm_number)
|
if(b_addr<0 || nasal_vm.gc_get(b_addr).get_type()!=vm_number)
|
||||||
{
|
{
|
||||||
std::cout<<">> [runtime] builtin_xor: \"b\" has wrong value type(must be number).\n";
|
std::cout<<">> [runtime] builtin_xor: \"b\" has wrong value type(must be number).\n";
|
||||||
++error;
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
int number_a=(int)nasal_vm.gc_get(a_addr).get_number();
|
int number_a=(int)nasal_vm.gc_get(a_addr).get_number();
|
||||||
|
@ -449,20 +523,18 @@ int nasal_runtime::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 nasal_runtime::builtin_and(int local_scope_addr)
|
int builtin_and(int local_scope_addr)
|
||||||
{
|
{
|
||||||
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");
|
||||||
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)
|
||||||
{
|
{
|
||||||
std::cout<<">> [runtime] builtin_and: \"a\" has wrong value type(must be number).\n";
|
std::cout<<">> [runtime] builtin_and: \"a\" has wrong value type(must be number).\n";
|
||||||
++error;
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if(b_addr<0 || nasal_vm.gc_get(b_addr).get_type()!=vm_number)
|
if(b_addr<0 || nasal_vm.gc_get(b_addr).get_type()!=vm_number)
|
||||||
{
|
{
|
||||||
std::cout<<">> [runtime] builtin_and: \"b\" has wrong value type(must be number).\n";
|
std::cout<<">> [runtime] builtin_and: \"b\" has wrong value type(must be number).\n";
|
||||||
++error;
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
int number_a=(int)nasal_vm.gc_get(a_addr).get_number();
|
int number_a=(int)nasal_vm.gc_get(a_addr).get_number();
|
||||||
|
@ -471,20 +543,18 @@ int nasal_runtime::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 nasal_runtime::builtin_or(int local_scope_addr)
|
int builtin_or(int local_scope_addr)
|
||||||
{
|
{
|
||||||
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");
|
||||||
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)
|
||||||
{
|
{
|
||||||
std::cout<<">> [runtime] builtin_or: \"a\" has wrong value type(must be number).\n";
|
std::cout<<">> [runtime] builtin_or: \"a\" has wrong value type(must be number).\n";
|
||||||
++error;
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if(b_addr<0 || nasal_vm.gc_get(b_addr).get_type()!=vm_number)
|
if(b_addr<0 || nasal_vm.gc_get(b_addr).get_type()!=vm_number)
|
||||||
{
|
{
|
||||||
std::cout<<">> [runtime] builtin_or: \"b\" has wrong value type(must be number).\n";
|
std::cout<<">> [runtime] builtin_or: \"b\" has wrong value type(must be number).\n";
|
||||||
++error;
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
int number_a=(int)nasal_vm.gc_get(a_addr).get_number();
|
int number_a=(int)nasal_vm.gc_get(a_addr).get_number();
|
||||||
|
@ -493,20 +563,18 @@ int nasal_runtime::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 nasal_runtime::builtin_nand(int local_scope_addr)
|
int builtin_nand(int local_scope_addr)
|
||||||
{
|
{
|
||||||
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");
|
||||||
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)
|
||||||
{
|
{
|
||||||
std::cout<<">> [runtime] builtin_nand: \"a\" has wrong value type(must be number).\n";
|
std::cout<<">> [runtime] builtin_nand: \"a\" has wrong value type(must be number).\n";
|
||||||
++error;
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if(b_addr<0 || nasal_vm.gc_get(b_addr).get_type()!=vm_number)
|
if(b_addr<0 || nasal_vm.gc_get(b_addr).get_type()!=vm_number)
|
||||||
{
|
{
|
||||||
std::cout<<">> [runtime] builtin_nand: \"b\" has wrong value type(must be number).\n";
|
std::cout<<">> [runtime] builtin_nand: \"b\" has wrong value type(must be number).\n";
|
||||||
++error;
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
int number_a=(int)nasal_vm.gc_get(a_addr).get_number();
|
int number_a=(int)nasal_vm.gc_get(a_addr).get_number();
|
||||||
|
@ -515,13 +583,12 @@ int nasal_runtime::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 nasal_runtime::builtin_not(int local_scope_addr)
|
int builtin_not(int local_scope_addr)
|
||||||
{
|
{
|
||||||
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)
|
||||||
{
|
{
|
||||||
std::cout<<">> [runtime] builtin_not: \"a\" has wrong value type(must be number).\n";
|
std::cout<<">> [runtime] builtin_not: \"a\" has wrong value type(must be number).\n";
|
||||||
++error;
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
int number=(int)nasal_vm.gc_get(a_addr).get_number();
|
int number=(int)nasal_vm.gc_get(a_addr).get_number();
|
||||||
|
@ -529,13 +596,12 @@ int nasal_runtime::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 nasal_runtime::builtin_sin(int local_scope_addr)
|
int builtin_sin(int local_scope_addr)
|
||||||
{
|
{
|
||||||
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)
|
||||||
{
|
{
|
||||||
std::cout<<">> [runtime] builtin_sin: \"x\" has wrong value type(must be number).\n";
|
std::cout<<">> [runtime] builtin_sin: \"x\" has wrong value type(must be number).\n";
|
||||||
++error;
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
double number=nasal_vm.gc_get(value_addr).get_number();
|
double number=nasal_vm.gc_get(value_addr).get_number();
|
||||||
|
@ -543,13 +609,12 @@ int nasal_runtime::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 nasal_runtime::builtin_cos(int local_scope_addr)
|
int builtin_cos(int local_scope_addr)
|
||||||
{
|
{
|
||||||
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)
|
||||||
{
|
{
|
||||||
std::cout<<">> [runtime] builtin_cos: \"x\" has wrong value type(must be number).\n";
|
std::cout<<">> [runtime] builtin_cos: \"x\" has wrong value type(must be number).\n";
|
||||||
++error;
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
double number=nasal_vm.gc_get(value_addr).get_number();
|
double number=nasal_vm.gc_get(value_addr).get_number();
|
||||||
|
@ -557,13 +622,12 @@ int nasal_runtime::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 nasal_runtime::builtin_tan(int local_scope_addr)
|
int builtin_tan(int local_scope_addr)
|
||||||
{
|
{
|
||||||
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)
|
||||||
{
|
{
|
||||||
std::cout<<">> [runtime] builtin_tan: \"x\" has wrong value type(must be number).\n";
|
std::cout<<">> [runtime] builtin_tan: \"x\" has wrong value type(must be number).\n";
|
||||||
++error;
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
double number=nasal_vm.gc_get(value_addr).get_number();
|
double number=nasal_vm.gc_get(value_addr).get_number();
|
||||||
|
@ -571,13 +635,12 @@ int nasal_runtime::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 nasal_runtime::builtin_exp(int local_scope_addr)
|
int builtin_exp(int local_scope_addr)
|
||||||
{
|
{
|
||||||
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)
|
||||||
{
|
{
|
||||||
std::cout<<">> [runtime] builtin_exp: \"x\" has wrong value type(must be number).\n";
|
std::cout<<">> [runtime] builtin_exp: \"x\" has wrong value type(must be number).\n";
|
||||||
++error;
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
double number=nasal_vm.gc_get(value_addr).get_number();
|
double number=nasal_vm.gc_get(value_addr).get_number();
|
||||||
|
@ -585,13 +648,12 @@ int nasal_runtime::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 nasal_runtime::builtin_ln(int local_scope_addr)
|
int builtin_ln(int local_scope_addr)
|
||||||
{
|
{
|
||||||
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)
|
||||||
{
|
{
|
||||||
std::cout<<">> [runtime] builtin_ln: \"x\" has wrong value type(must be number).\n";
|
std::cout<<">> [runtime] builtin_ln: \"x\" has wrong value type(must be number).\n";
|
||||||
++error;
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
double number=nasal_vm.gc_get(value_addr).get_number();
|
double number=nasal_vm.gc_get(value_addr).get_number();
|
||||||
|
@ -599,13 +661,12 @@ int nasal_runtime::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 nasal_runtime::builtin_sqrt(int local_scope_addr)
|
int builtin_sqrt(int local_scope_addr)
|
||||||
{
|
{
|
||||||
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)
|
||||||
{
|
{
|
||||||
std::cout<<">> [runtime] builtin_sqrt: \"x\" has wrong value type(must be number).\n";
|
std::cout<<">> [runtime] builtin_sqrt: \"x\" has wrong value type(must be number).\n";
|
||||||
++error;
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
double number=nasal_vm.gc_get(value_addr).get_number();
|
double number=nasal_vm.gc_get(value_addr).get_number();
|
||||||
|
@ -613,20 +674,18 @@ int nasal_runtime::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 nasal_runtime::builtin_atan2(int local_scope_addr)
|
int builtin_atan2(int local_scope_addr)
|
||||||
{
|
{
|
||||||
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");
|
||||||
if(x_value_addr<0 || nasal_vm.gc_get(x_value_addr).get_type()!=vm_number)
|
if(x_value_addr<0 || nasal_vm.gc_get(x_value_addr).get_type()!=vm_number)
|
||||||
{
|
{
|
||||||
std::cout<<">> [runtime] builtin_atan2: \"x\" has wrong value type(must be number).\n";
|
std::cout<<">> [runtime] builtin_atan2: \"x\" has wrong value type(must be number).\n";
|
||||||
++error;
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if(y_value_addr<0 || nasal_vm.gc_get(y_value_addr).get_type()!=vm_number)
|
if(y_value_addr<0 || nasal_vm.gc_get(y_value_addr).get_type()!=vm_number)
|
||||||
{
|
{
|
||||||
std::cout<<">> [runtime] builtin_atan2: \"y\" has wrong value type(must be number).\n";
|
std::cout<<">> [runtime] builtin_atan2: \"y\" has wrong value type(must be number).\n";
|
||||||
++error;
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
double x=nasal_vm.gc_get(x_value_addr).get_number();
|
double x=nasal_vm.gc_get(x_value_addr).get_number();
|
||||||
|
@ -635,13 +694,12 @@ int nasal_runtime::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 nasal_runtime::builtin_time(int local_scope_addr)
|
int builtin_time(int local_scope_addr)
|
||||||
{
|
{
|
||||||
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)
|
||||||
{
|
{
|
||||||
std::cout<<">> [runtime] builtin_time: \"begin_time\" has wrong value type(must be number).\n";
|
std::cout<<">> [runtime] builtin_time: \"begin_time\" has wrong value type(must be number).\n";
|
||||||
++error;
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
time_t begin_time=(time_t)nasal_vm.gc_get(value_addr).get_number();
|
time_t begin_time=(time_t)nasal_vm.gc_get(value_addr).get_number();
|
||||||
|
@ -649,20 +707,18 @@ int nasal_runtime::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 nasal_runtime::builtin_contains(int local_scope_addr)
|
int builtin_contains(int local_scope_addr)
|
||||||
{
|
{
|
||||||
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");
|
||||||
if(hash_addr<0 || !in_builtin_check(hash_addr,vm_hash))
|
if(hash_addr<0 || !in_builtin_check(hash_addr,vm_hash))
|
||||||
{
|
{
|
||||||
std::cout<<">> [runtime] builtin_contains: \"hash\" has wrong type(must be hash).\n";
|
std::cout<<">> [runtime] builtin_contains: \"hash\" has wrong type(must be hash).\n";
|
||||||
++error;
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if(key_addr<0 || !in_builtin_check(key_addr,vm_string))
|
if(key_addr<0 || !in_builtin_check(key_addr,vm_string))
|
||||||
{
|
{
|
||||||
std::cout<<">> [runtime] builtin_contains: \"key\" has wrong type(must be string).\n";
|
std::cout<<">> [runtime] builtin_contains: \"key\" has wrong type(must be string).\n";
|
||||||
++error;
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
std::string key=nasal_vm.gc_get(key_addr).get_string();
|
std::string key=nasal_vm.gc_get(key_addr).get_string();
|
||||||
|
@ -671,20 +727,18 @@ int nasal_runtime::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 nasal_runtime::builtin_delete(int local_scope_addr)
|
int builtin_delete(int local_scope_addr)
|
||||||
{
|
{
|
||||||
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");
|
||||||
if(hash_addr<0 || !in_builtin_check(hash_addr,vm_hash))
|
if(hash_addr<0 || !in_builtin_check(hash_addr,vm_hash))
|
||||||
{
|
{
|
||||||
std::cout<<">> [runtime] builtin_delete: \"hash\" has wrong type(must be hash).\n";
|
std::cout<<">> [runtime] builtin_delete: \"hash\" has wrong type(must be hash).\n";
|
||||||
++error;
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if(key_addr<0 || !in_builtin_check(key_addr,vm_string))
|
if(key_addr<0 || !in_builtin_check(key_addr,vm_string))
|
||||||
{
|
{
|
||||||
std::cout<<">> [runtime] builtin_delete: \"key\" has wrong type(must be string).\n";
|
std::cout<<">> [runtime] builtin_delete: \"key\" has wrong type(must be string).\n";
|
||||||
++error;
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
std::string key=nasal_vm.gc_get(key_addr).get_string();
|
std::string key=nasal_vm.gc_get(key_addr).get_string();
|
||||||
|
@ -692,48 +746,44 @@ int nasal_runtime::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 nasal_runtime::builtin_getkeys(int local_scope_addr)
|
int builtin_getkeys(int local_scope_addr)
|
||||||
{
|
{
|
||||||
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))
|
||||||
{
|
{
|
||||||
std::cout<<">> [runtime] builtin_delete: \"hash\" has wrong type(must be hash).\n";
|
std::cout<<">> [runtime] builtin_delete: \"hash\" has wrong type(must be hash).\n";
|
||||||
++error;
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
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 nasal_runtime::builtin_import(int local_scope_addr)
|
int builtin_import(int local_scope_addr)
|
||||||
{
|
{
|
||||||
// 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.
|
||||||
++error;
|
|
||||||
std::cout<<">> [runtime] builtin_import: cannot use import when running.\n";
|
std::cout<<">> [runtime] builtin_import: cannot use import when running.\n";
|
||||||
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 nasal_runtime::builtin_die(int local_scope_addr)
|
int builtin_die(int local_scope_addr)
|
||||||
{
|
{
|
||||||
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))
|
||||||
{
|
{
|
||||||
std::cout<<">> [runtime] builtin_die: \"str\" has wrong type(must be string).\n";
|
std::cout<<">> [runtime] builtin_die: \"str\" has wrong type(must be string).\n";
|
||||||
++error;
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
++error;
|
builtin_die_state=1;
|
||||||
std::cout<<">> [runtime] error: "<<nasal_vm.gc_get(str_addr).get_string()<<'\n';
|
std::cout<<">> [runtime] error: "<<nasal_vm.gc_get(str_addr).get_string()<<'\n';
|
||||||
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 nasal_runtime::builtin_type(int local_scope_addr)
|
int builtin_type(int local_scope_addr)
|
||||||
{
|
{
|
||||||
int value_addr=in_builtin_find("object");
|
int value_addr=in_builtin_find("object");
|
||||||
if(value_addr<0)
|
if(value_addr<0)
|
||||||
{
|
{
|
||||||
std::cout<<">> [runtime] builtin_type: cannot find \"object\".\n";
|
std::cout<<">> [runtime] builtin_type: cannot find \"object\".\n";
|
||||||
++error;
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
int type=nasal_vm.gc_get(value_addr).get_type();
|
int type=nasal_vm.gc_get(value_addr).get_type();
|
||||||
|
@ -749,7 +799,7 @@ int nasal_runtime::builtin_type(int local_scope_addr)
|
||||||
}
|
}
|
||||||
return ret_addr;
|
return ret_addr;
|
||||||
}
|
}
|
||||||
int nasal_runtime::builtin_substr(int local_scope_addr)
|
int builtin_substr(int local_scope_addr)
|
||||||
{
|
{
|
||||||
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");
|
||||||
|
@ -757,19 +807,16 @@ int nasal_runtime::builtin_substr(int local_scope_addr)
|
||||||
if(str_addr<0 || !in_builtin_check(str_addr,vm_string))
|
if(str_addr<0 || !in_builtin_check(str_addr,vm_string))
|
||||||
{
|
{
|
||||||
std::cout<<">> [runtime] builtin_substr: cannot find \"str\" or wrong type(must be string).\n";
|
std::cout<<">> [runtime] builtin_substr: cannot find \"str\" or wrong type(must be string).\n";
|
||||||
++error;
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if(begin_addr<0 || !in_builtin_check(begin_addr,vm_number))
|
if(begin_addr<0 || !in_builtin_check(begin_addr,vm_number))
|
||||||
{
|
{
|
||||||
std::cout<<">> [runtime] builtin_substr: cannot find \"begin\" or wrong type(must be number).\n";
|
std::cout<<">> [runtime] builtin_substr: cannot find \"begin\" or wrong type(must be number).\n";
|
||||||
++error;
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if(length_addr<0 || !in_builtin_check(length_addr,vm_number))
|
if(length_addr<0 || !in_builtin_check(length_addr,vm_number))
|
||||||
{
|
{
|
||||||
std::cout<<">> [runtime] builtin_substr: cannot find \"length\" or wrong type(must be number).\n";
|
std::cout<<">> [runtime] builtin_substr: cannot find \"length\" or wrong type(must be number).\n";
|
||||||
++error;
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
std::string str=nasal_vm.gc_get(str_addr).get_string();
|
std::string str=nasal_vm.gc_get(str_addr).get_string();
|
||||||
|
@ -778,7 +825,6 @@ int nasal_runtime::builtin_substr(int local_scope_addr)
|
||||||
if(begin>=str.length() || begin+len>=str.length())
|
if(begin>=str.length() || begin+len>=str.length())
|
||||||
{
|
{
|
||||||
std::cout<<">> [runtime] builtin_substr: index out of range.\n";
|
std::cout<<">> [runtime] builtin_substr: index out of range.\n";
|
||||||
++error;
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
std::string tmp="";
|
std::string tmp="";
|
||||||
|
|
49
nasal_gc.h
49
nasal_gc.h
|
@ -132,7 +132,6 @@ class nasal_virtual_machine
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
private:
|
private:
|
||||||
bool error_info_output_switch;
|
|
||||||
nasal_scalar error_returned_value;
|
nasal_scalar error_returned_value;
|
||||||
std::queue<int> garbage_collector_free_space;
|
std::queue<int> garbage_collector_free_space;
|
||||||
std::vector<gc_unit*> garbage_collector_memory;
|
std::vector<gc_unit*> garbage_collector_memory;
|
||||||
|
@ -148,8 +147,8 @@ public:
|
||||||
void add_reference(int);
|
void add_reference(int);
|
||||||
void del_reference(int);
|
void del_reference(int);
|
||||||
int mem_alloc(int); // memory gives a new space
|
int mem_alloc(int); // memory gives a new space
|
||||||
int mem_free(int); // give space back to memory
|
void mem_free(int); // give space back to memory
|
||||||
int mem_change(int,int); // change value in memory space
|
void mem_change(int,int); // change value in memory space
|
||||||
int mem_get(int); // get value in memory space
|
int mem_get(int); // get value in memory space
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1092,12 +1091,10 @@ int nasal_scalar::nasal_scalar_cmp_greater_or_equal(int a_scalar_addr,int b_scal
|
||||||
/*functions of nasal_virtual_machine*/
|
/*functions of nasal_virtual_machine*/
|
||||||
nasal_virtual_machine::nasal_virtual_machine()
|
nasal_virtual_machine::nasal_virtual_machine()
|
||||||
{
|
{
|
||||||
error_info_output_switch=true;
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
nasal_virtual_machine::~nasal_virtual_machine()
|
nasal_virtual_machine::~nasal_virtual_machine()
|
||||||
{
|
{
|
||||||
error_info_output_switch=false;
|
|
||||||
int gc_mem_size=garbage_collector_memory.size();
|
int gc_mem_size=garbage_collector_memory.size();
|
||||||
int mm_mem_size=memory_manager_memory.size();
|
int mm_mem_size=memory_manager_memory.size();
|
||||||
for(int i=0;i<gc_mem_size;++i)
|
for(int i=0;i<gc_mem_size;++i)
|
||||||
|
@ -1123,7 +1120,6 @@ nasal_virtual_machine::~nasal_virtual_machine()
|
||||||
memory_manager_free_space.pop();
|
memory_manager_free_space.pop();
|
||||||
garbage_collector_memory.clear();
|
garbage_collector_memory.clear();
|
||||||
memory_manager_memory.clear();
|
memory_manager_memory.clear();
|
||||||
error_info_output_switch=true;
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
void nasal_virtual_machine::debug()
|
void nasal_virtual_machine::debug()
|
||||||
|
@ -1151,7 +1147,6 @@ void nasal_virtual_machine::debug()
|
||||||
}
|
}
|
||||||
void nasal_virtual_machine::clear()
|
void nasal_virtual_machine::clear()
|
||||||
{
|
{
|
||||||
error_info_output_switch=false;
|
|
||||||
int gc_mem_size=garbage_collector_memory.size();
|
int gc_mem_size=garbage_collector_memory.size();
|
||||||
int mm_mem_size=memory_manager_memory.size();
|
int mm_mem_size=memory_manager_memory.size();
|
||||||
for(int i=0;i<gc_mem_size;++i)
|
for(int i=0;i<gc_mem_size;++i)
|
||||||
|
@ -1177,7 +1172,6 @@ void nasal_virtual_machine::clear()
|
||||||
memory_manager_free_space.pop();
|
memory_manager_free_space.pop();
|
||||||
garbage_collector_memory.clear();
|
garbage_collector_memory.clear();
|
||||||
memory_manager_memory.clear();
|
memory_manager_memory.clear();
|
||||||
error_info_output_switch=true;
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
int nasal_virtual_machine::gc_alloc(int val_type)
|
int nasal_virtual_machine::gc_alloc(int val_type)
|
||||||
|
@ -1206,12 +1200,7 @@ nasal_scalar& nasal_virtual_machine::gc_get(int value_address)
|
||||||
int blk_plc=(value_address&0xff);
|
int blk_plc=(value_address&0xff);
|
||||||
if(0<=value_address && value_address<(garbage_collector_memory.size()<<8) && !garbage_collector_memory[blk_num][blk_plc].collected)
|
if(0<=value_address && value_address<(garbage_collector_memory.size()<<8) && !garbage_collector_memory[blk_num][blk_plc].collected)
|
||||||
return garbage_collector_memory[blk_num][blk_plc].elem;
|
return garbage_collector_memory[blk_num][blk_plc].elem;
|
||||||
else
|
|
||||||
{
|
|
||||||
if(error_info_output_switch)
|
|
||||||
std::cout<<">> [vm] gc_get:unexpected memory \'"<<value_address<<"\'.\n";
|
|
||||||
return error_returned_value;
|
return error_returned_value;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
void nasal_virtual_machine::add_reference(int value_address)
|
void nasal_virtual_machine::add_reference(int value_address)
|
||||||
{
|
{
|
||||||
|
@ -1219,11 +1208,6 @@ void nasal_virtual_machine::add_reference(int value_address)
|
||||||
int blk_plc=(value_address&0xff);
|
int blk_plc=(value_address&0xff);
|
||||||
if(0<=value_address && value_address<(garbage_collector_memory.size()<<8) && !garbage_collector_memory[blk_num][blk_plc].collected)
|
if(0<=value_address && value_address<(garbage_collector_memory.size()<<8) && !garbage_collector_memory[blk_num][blk_plc].collected)
|
||||||
++garbage_collector_memory[blk_num][blk_plc].ref_cnt;
|
++garbage_collector_memory[blk_num][blk_plc].ref_cnt;
|
||||||
else
|
|
||||||
{
|
|
||||||
if(error_info_output_switch)
|
|
||||||
std::cout<<">> [vm] gc_add_ref:unexpected memory \'"<<value_address<<"\'.\n";
|
|
||||||
}
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
void nasal_virtual_machine::del_reference(int value_address)
|
void nasal_virtual_machine::del_reference(int value_address)
|
||||||
|
@ -1233,11 +1217,7 @@ void nasal_virtual_machine::del_reference(int value_address)
|
||||||
if(0<=value_address && value_address<(garbage_collector_memory.size()<<8) && !garbage_collector_memory[blk_num][blk_plc].collected)
|
if(0<=value_address && value_address<(garbage_collector_memory.size()<<8) && !garbage_collector_memory[blk_num][blk_plc].collected)
|
||||||
--garbage_collector_memory[blk_num][blk_plc].ref_cnt;
|
--garbage_collector_memory[blk_num][blk_plc].ref_cnt;
|
||||||
else
|
else
|
||||||
{
|
|
||||||
if(error_info_output_switch)
|
|
||||||
std::cout<<">> [vm] gc_del_ref:unexpected memory \'"<<value_address<<"\'.\n";
|
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
if(!garbage_collector_memory[blk_num][blk_plc].ref_cnt)
|
if(!garbage_collector_memory[blk_num][blk_plc].ref_cnt)
|
||||||
{
|
{
|
||||||
garbage_collector_memory[blk_num][blk_plc].collected=true;
|
garbage_collector_memory[blk_num][blk_plc].collected=true;
|
||||||
|
@ -1261,7 +1241,7 @@ int nasal_virtual_machine::mem_alloc(int value_address)
|
||||||
memory_manager_free_space.pop();
|
memory_manager_free_space.pop();
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
int nasal_virtual_machine::mem_free(int memory_address)
|
void nasal_virtual_machine::mem_free(int memory_address)
|
||||||
{
|
{
|
||||||
// mem_free has helped scalar to delete the reference
|
// mem_free has helped scalar to delete the reference
|
||||||
// so don't need to delete reference again
|
// so don't need to delete reference again
|
||||||
|
@ -1270,15 +1250,9 @@ int nasal_virtual_machine::mem_free(int memory_address)
|
||||||
this->del_reference(memory_manager_memory[memory_address>>8][memory_address&0xff]);
|
this->del_reference(memory_manager_memory[memory_address>>8][memory_address&0xff]);
|
||||||
memory_manager_free_space.push(memory_address);
|
memory_manager_free_space.push(memory_address);
|
||||||
}
|
}
|
||||||
else
|
return;
|
||||||
{
|
|
||||||
if(error_info_output_switch)
|
|
||||||
std::cout<<">> [vm] mem_free:unexpected memory \'"<<memory_address<<"\'.\n";
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
return 1;
|
|
||||||
}
|
}
|
||||||
int nasal_virtual_machine::mem_change(int memory_address,int value_address)
|
void nasal_virtual_machine::mem_change(int memory_address,int value_address)
|
||||||
{
|
{
|
||||||
// this progress is used to change a memory space's value address
|
// this progress is used to change a memory space's value address
|
||||||
// be careful! this process doesn't check if this mem_space is in use.
|
// be careful! this process doesn't check if this mem_space is in use.
|
||||||
|
@ -1287,13 +1261,7 @@ int nasal_virtual_machine::mem_change(int memory_address,int value_address)
|
||||||
this->del_reference(memory_manager_memory[memory_address>>8][memory_address&0xff]);
|
this->del_reference(memory_manager_memory[memory_address>>8][memory_address&0xff]);
|
||||||
memory_manager_memory[memory_address>>8][memory_address&0xff]=value_address;
|
memory_manager_memory[memory_address>>8][memory_address&0xff]=value_address;
|
||||||
}
|
}
|
||||||
else
|
return;
|
||||||
{
|
|
||||||
if(error_info_output_switch)
|
|
||||||
std::cout<<">> [vm] mem_change:unexpected memory \'"<<memory_address<<"\'.\n";
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
return 1;
|
|
||||||
}
|
}
|
||||||
int nasal_virtual_machine::mem_get(int memory_address)
|
int nasal_virtual_machine::mem_get(int memory_address)
|
||||||
{
|
{
|
||||||
|
@ -1301,11 +1269,6 @@ int nasal_virtual_machine::mem_get(int memory_address)
|
||||||
// be careful! this process doesn't check if this mem_space is in use.
|
// be careful! this process doesn't check if this mem_space is in use.
|
||||||
if(0<=memory_address && memory_address<(memory_manager_memory.size()<<8))
|
if(0<=memory_address && memory_address<(memory_manager_memory.size()<<8))
|
||||||
ret=memory_manager_memory[memory_address>>8][memory_address&0xff];
|
ret=memory_manager_memory[memory_address>>8][memory_address&0xff];
|
||||||
else
|
|
||||||
{
|
|
||||||
if(error_info_output_switch)
|
|
||||||
std::cout<<">> [vm] mem_get:unexpected memory \'"<<memory_address<<"\'.\n";
|
|
||||||
}
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
|
@ -19,7 +19,7 @@ private:
|
||||||
public:
|
public:
|
||||||
nasal_import();
|
nasal_import();
|
||||||
int get_error();
|
int get_error();
|
||||||
void preprocessing(nasal_ast&);
|
void link(nasal_ast&);
|
||||||
nasal_ast& get_root();
|
nasal_ast& get_root();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -153,7 +153,7 @@ nasal_ast nasal_import::load(nasal_ast& root)
|
||||||
return new_root;
|
return new_root;
|
||||||
}
|
}
|
||||||
|
|
||||||
void nasal_import::preprocessing(nasal_ast& root)
|
void nasal_import::link(nasal_ast& root)
|
||||||
{
|
{
|
||||||
// initializing
|
// initializing
|
||||||
error=0;
|
error=0;
|
||||||
|
|
|
@ -83,11 +83,10 @@ private:
|
||||||
nasal_ast call_func();
|
nasal_ast call_func();
|
||||||
nasal_ast subvec();
|
nasal_ast subvec();
|
||||||
nasal_ast definition();
|
nasal_ast definition();
|
||||||
nasal_ast normal_def();
|
|
||||||
nasal_ast var_incurve_def();
|
nasal_ast var_incurve_def();
|
||||||
nasal_ast var_outcurve_def();
|
nasal_ast var_outcurve_def();
|
||||||
nasal_ast multi_id();
|
nasal_ast multi_id();
|
||||||
nasal_ast multi_scalar();
|
nasal_ast multi_scalar(bool);
|
||||||
nasal_ast multi_assgin();
|
nasal_ast multi_assgin();
|
||||||
nasal_ast loop();
|
nasal_ast loop();
|
||||||
nasal_ast while_loop();
|
nasal_ast while_loop();
|
||||||
|
@ -672,6 +671,8 @@ nasal_ast nasal_parse::calculation()
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
|
if(node.get_type()!=ast_call && node.get_type()!=ast_identifier)
|
||||||
|
die(node.get_line(),"cannot use calculation as the memory of scalar");
|
||||||
// assignment
|
// assignment
|
||||||
nasal_ast tmp;
|
nasal_ast tmp;
|
||||||
tmp.set_line(tok_list[ptr].line);
|
tmp.set_line(tok_list[ptr].line);
|
||||||
|
@ -1085,7 +1086,7 @@ nasal_ast nasal_parse::definition()
|
||||||
++ptr;
|
++ptr;
|
||||||
switch(tok_list[ptr].type)
|
switch(tok_list[ptr].type)
|
||||||
{
|
{
|
||||||
case tok_identifier:node.add_child(normal_def()); break;
|
case tok_identifier:node.add_child(id_gen()); break;
|
||||||
case tok_left_curve:node.add_child(var_outcurve_def()); break;
|
case tok_left_curve:node.add_child(var_outcurve_def()); break;
|
||||||
default:
|
default:
|
||||||
die(error_line,"expected identifier");
|
die(error_line,"expected identifier");
|
||||||
|
@ -1107,17 +1108,11 @@ nasal_ast nasal_parse::definition()
|
||||||
return node;
|
return node;
|
||||||
}
|
}
|
||||||
if(tok_list[ptr].type==tok_left_curve)
|
if(tok_list[ptr].type==tok_left_curve)
|
||||||
node.add_child(check_multi_scalar()?multi_scalar():calculation());
|
node.add_child(check_multi_scalar()?multi_scalar(false):calculation());
|
||||||
else
|
else
|
||||||
node.add_child(calculation());
|
node.add_child(calculation());
|
||||||
return node;
|
if(node.get_children()[0].get_type()==ast_identifier && node.get_children()[1].get_type()==ast_multi_scalar)
|
||||||
}
|
die(node.get_children()[1].get_line(),"one identifier cannot accept too many values");
|
||||||
nasal_ast nasal_parse::normal_def()
|
|
||||||
{
|
|
||||||
nasal_ast node;
|
|
||||||
node.set_line(tok_list[ptr].line);
|
|
||||||
node.set_str(tok_list[ptr].str);
|
|
||||||
node.set_type(ast_identifier);
|
|
||||||
return node;
|
return node;
|
||||||
}
|
}
|
||||||
nasal_ast nasal_parse::var_incurve_def()
|
nasal_ast nasal_parse::var_incurve_def()
|
||||||
|
@ -1178,8 +1173,9 @@ nasal_ast nasal_parse::multi_id()
|
||||||
}
|
}
|
||||||
return node;
|
return node;
|
||||||
}
|
}
|
||||||
nasal_ast nasal_parse::multi_scalar()
|
nasal_ast nasal_parse::multi_scalar(bool check_call_memory)
|
||||||
{
|
{
|
||||||
|
// if check_call_memory is true,we will check if value called here can reach a memory space
|
||||||
nasal_ast node;
|
nasal_ast node;
|
||||||
node.set_line(tok_list[ptr].line);
|
node.set_line(tok_list[ptr].line);
|
||||||
node.set_type(ast_multi_scalar);
|
node.set_type(ast_multi_scalar);
|
||||||
|
@ -1187,6 +1183,9 @@ nasal_ast nasal_parse::multi_scalar()
|
||||||
while(ptr<tok_list_size && tok_list[ptr].type!=tok_right_curve)
|
while(ptr<tok_list_size && tok_list[ptr].type!=tok_right_curve)
|
||||||
{
|
{
|
||||||
node.add_child(calculation());
|
node.add_child(calculation());
|
||||||
|
int type=node.get_children().back().get_type();
|
||||||
|
if(check_call_memory && type!=ast_call && type!=ast_identifier)
|
||||||
|
die(node.get_children().back().get_line(),"cannot use calculation as the memory of scalar");
|
||||||
++ptr;
|
++ptr;
|
||||||
if(ptr>=tok_list_size)
|
if(ptr>=tok_list_size)
|
||||||
break;
|
break;
|
||||||
|
@ -1204,7 +1203,7 @@ nasal_ast nasal_parse::multi_assgin()
|
||||||
nasal_ast node;
|
nasal_ast node;
|
||||||
node.set_line(tok_list[ptr].line);
|
node.set_line(tok_list[ptr].line);
|
||||||
node.set_type(ast_multi_assign);
|
node.set_type(ast_multi_assign);
|
||||||
node.add_child(multi_scalar());
|
node.add_child(multi_scalar(true));
|
||||||
++ptr;
|
++ptr;
|
||||||
if(ptr>=tok_list_size || tok_list[ptr].type!=tok_equal)
|
if(ptr>=tok_list_size || tok_list[ptr].type!=tok_equal)
|
||||||
{
|
{
|
||||||
|
@ -1218,7 +1217,7 @@ nasal_ast nasal_parse::multi_assgin()
|
||||||
return node;
|
return node;
|
||||||
}
|
}
|
||||||
if(tok_list[ptr].type==tok_left_curve)
|
if(tok_list[ptr].type==tok_left_curve)
|
||||||
node.add_child(check_multi_scalar()?multi_scalar():calculation());
|
node.add_child(check_multi_scalar()?multi_scalar(false):calculation());
|
||||||
else
|
else
|
||||||
node.add_child(calculation());
|
node.add_child(calculation());
|
||||||
return node;
|
return node;
|
||||||
|
|
104
nasal_runtime.h
104
nasal_runtime.h
|
@ -13,7 +13,7 @@ enum runtime_returned_state
|
||||||
class nasal_runtime
|
class nasal_runtime
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
std::map<std::string,int (nasal_runtime::*)(int x)> builtin_func_hashmap;
|
std::map<std::string,int (*)(int x)> 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
|
||||||
|
@ -64,42 +64,6 @@ private:
|
||||||
void multi_assignment(nasal_ast&,int);
|
void multi_assignment(nasal_ast&,int);
|
||||||
|
|
||||||
// builtin_func defined here
|
// builtin_func defined here
|
||||||
int builtin_print(int);
|
|
||||||
int builtin_append(int);
|
|
||||||
int builtin_setsize(int);
|
|
||||||
int builtin_system(int);
|
|
||||||
int builtin_input(int);
|
|
||||||
int builtin_sleep(int);
|
|
||||||
int builtin_finput(int);
|
|
||||||
int builtin_foutput(int);
|
|
||||||
int builtin_split(int);
|
|
||||||
int builtin_rand(int);
|
|
||||||
int builtin_id(int);
|
|
||||||
int builtin_int(int);
|
|
||||||
int builtin_num(int);
|
|
||||||
int builtin_pop(int);
|
|
||||||
int builtin_str(int);
|
|
||||||
int builtin_size(int);
|
|
||||||
int builtin_xor(int);
|
|
||||||
int builtin_and(int);
|
|
||||||
int builtin_or(int);
|
|
||||||
int builtin_nand(int);
|
|
||||||
int builtin_not(int);
|
|
||||||
int builtin_sin(int);
|
|
||||||
int builtin_cos(int);
|
|
||||||
int builtin_tan(int);
|
|
||||||
int builtin_exp(int);
|
|
||||||
int builtin_ln(int);
|
|
||||||
int builtin_sqrt(int);
|
|
||||||
int builtin_atan2(int);
|
|
||||||
int builtin_time(int);
|
|
||||||
int builtin_contains(int);
|
|
||||||
int builtin_delete(int);
|
|
||||||
int builtin_getkeys(int);
|
|
||||||
int builtin_import(int);
|
|
||||||
int builtin_die(int);
|
|
||||||
int builtin_type(int);
|
|
||||||
int builtin_substr(int);
|
|
||||||
void load_builtin_function();
|
void load_builtin_function();
|
||||||
public:
|
public:
|
||||||
nasal_runtime();
|
nasal_runtime();
|
||||||
|
@ -132,50 +96,6 @@ void nasal_runtime::die(int line,std::string info)
|
||||||
}
|
}
|
||||||
void nasal_runtime::load_builtin_function()
|
void nasal_runtime::load_builtin_function()
|
||||||
{
|
{
|
||||||
struct FUNC_TABLE
|
|
||||||
{
|
|
||||||
std::string func_name;
|
|
||||||
int (nasal_runtime::*func_pointer)(int x);
|
|
||||||
} builtin_func_table[]=
|
|
||||||
{
|
|
||||||
{"nasal_call_builtin_std_cout", nasal_runtime::builtin_print},
|
|
||||||
{"nasal_call_builtin_push_back", nasal_runtime::builtin_append},
|
|
||||||
{"nasal_call_builtin_set_size", nasal_runtime::builtin_setsize},
|
|
||||||
{"nasal_call_builtin_system", nasal_runtime::builtin_system},
|
|
||||||
{"nasal_call_builtin_input", nasal_runtime::builtin_input},
|
|
||||||
{"nasal_call_builtin_sleep", nasal_runtime::builtin_sleep},
|
|
||||||
{"nasal_call_builtin_finput", nasal_runtime::builtin_finput},
|
|
||||||
{"nasal_call_builtin_foutput", nasal_runtime::builtin_foutput},
|
|
||||||
{"nasal_call_builtin_split", nasal_runtime::builtin_split},
|
|
||||||
{"nasal_call_builtin_rand", nasal_runtime::builtin_rand},
|
|
||||||
{"nasal_call_builtin_get_id", nasal_runtime::builtin_id},
|
|
||||||
{"nasal_call_builtin_trans_int", nasal_runtime::builtin_int},
|
|
||||||
{"nasal_call_builtin_trans_num", nasal_runtime::builtin_num},
|
|
||||||
{"nasal_call_builtin_pop_back", nasal_runtime::builtin_pop},
|
|
||||||
{"nasal_call_builtin_trans_str", nasal_runtime::builtin_str},
|
|
||||||
{"nasal_call_builtin_size", nasal_runtime::builtin_size},
|
|
||||||
{"nasal_call_builtin_xor", nasal_runtime::builtin_xor},
|
|
||||||
{"nasal_call_builtin_and", nasal_runtime::builtin_and},
|
|
||||||
{"nasal_call_builtin_or", nasal_runtime::builtin_or},
|
|
||||||
{"nasal_call_builtin_nand", nasal_runtime::builtin_nand},
|
|
||||||
{"nasal_call_builtin_not", nasal_runtime::builtin_not},
|
|
||||||
{"nasal_call_builtin_sin", nasal_runtime::builtin_sin},
|
|
||||||
{"nasal_call_builtin_cos", nasal_runtime::builtin_cos},
|
|
||||||
{"nasal_call_builtin_tan", nasal_runtime::builtin_tan},
|
|
||||||
{"nasal_call_builtin_exp", nasal_runtime::builtin_exp},
|
|
||||||
{"nasal_call_builtin_cpp_math_ln", nasal_runtime::builtin_ln},
|
|
||||||
{"nasal_call_builtin_cpp_math_sqrt", nasal_runtime::builtin_sqrt},
|
|
||||||
{"nasal_call_builtin_cpp_atan2", nasal_runtime::builtin_atan2},
|
|
||||||
{"nasal_call_builtin_time", nasal_runtime::builtin_time},
|
|
||||||
{"nasal_call_builtin_contains", nasal_runtime::builtin_contains},
|
|
||||||
{"nasal_call_builtin_delete", nasal_runtime::builtin_delete},
|
|
||||||
{"nasal_call_builtin_get_keys", nasal_runtime::builtin_getkeys},
|
|
||||||
{"nasal_call_import", nasal_runtime::builtin_import},
|
|
||||||
{"nasal_call_builtin_die", nasal_runtime::builtin_die},
|
|
||||||
{"nasal_call_builtin_type", nasal_runtime::builtin_type},
|
|
||||||
{"nasal_call_builtin_substr", nasal_runtime::builtin_substr},
|
|
||||||
{"", NULL}
|
|
||||||
};
|
|
||||||
for(int i=0;builtin_func_table[i].func_pointer;++i)
|
for(int i=0;builtin_func_table[i].func_pointer;++i)
|
||||||
builtin_func_hashmap[builtin_func_table[i].func_name]=builtin_func_table[i].func_pointer;
|
builtin_func_hashmap[builtin_func_table[i].func_name]=builtin_func_table[i].func_pointer;
|
||||||
return;
|
return;
|
||||||
|
@ -187,6 +107,9 @@ void nasal_runtime::set_root(nasal_ast& parse_result)
|
||||||
}
|
}
|
||||||
void nasal_runtime::run()
|
void nasal_runtime::run()
|
||||||
{
|
{
|
||||||
|
// this state is reserved for builtin_die
|
||||||
|
builtin_die_state=0;
|
||||||
|
|
||||||
this->error=0;
|
this->error=0;
|
||||||
this->function_returned_address=-1;
|
this->function_returned_address=-1;
|
||||||
|
|
||||||
|
@ -582,8 +505,7 @@ int nasal_runtime::call_scalar(nasal_ast& node,int local_scope_addr)
|
||||||
value_address=call_builtin_function(val_name,local_scope_addr);
|
value_address=call_builtin_function(val_name,local_scope_addr);
|
||||||
if(value_address>=0)
|
if(value_address>=0)
|
||||||
return value_address;
|
return value_address;
|
||||||
}
|
else
|
||||||
if(value_address<0)
|
|
||||||
{
|
{
|
||||||
if(builtin_func_hashmap.find(val_name)!=builtin_func_hashmap.end())
|
if(builtin_func_hashmap.find(val_name)!=builtin_func_hashmap.end())
|
||||||
die(node.get_children()[0].get_line(),"call "+val_name+" failed");
|
die(node.get_children()[0].get_line(),"call "+val_name+" failed");
|
||||||
|
@ -591,6 +513,7 @@ int nasal_runtime::call_scalar(nasal_ast& node,int local_scope_addr)
|
||||||
die(node.get_children()[0].get_line()," cannot find \""+val_name+"\"");
|
die(node.get_children()[0].get_line()," cannot find \""+val_name+"\"");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
nasal_vm.add_reference(value_address);
|
nasal_vm.add_reference(value_address);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -1042,7 +965,10 @@ int nasal_runtime::call_builtin_function(std::string val_name,int local_scope_ad
|
||||||
int ret_value_addr=-1;
|
int ret_value_addr=-1;
|
||||||
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=(this->*builtin_func_hashmap[val_name])(local_scope_addr);
|
{
|
||||||
|
ret_value_addr=(*builtin_func_hashmap[val_name])(local_scope_addr);
|
||||||
|
error+=builtin_die_state;
|
||||||
|
}
|
||||||
return ret_value_addr;
|
return ret_value_addr;
|
||||||
}
|
}
|
||||||
int nasal_runtime::call_scalar_mem(nasal_ast& node,int local_scope_addr)
|
int nasal_runtime::call_scalar_mem(nasal_ast& node,int local_scope_addr)
|
||||||
|
@ -1468,11 +1394,6 @@ void nasal_runtime::definition(nasal_ast& node,int local_scope_addr)
|
||||||
{
|
{
|
||||||
nasal_ast& define_node=node.get_children()[0];
|
nasal_ast& define_node=node.get_children()[0];
|
||||||
nasal_ast& value_node=node.get_children()[1];
|
nasal_ast& value_node=node.get_children()[1];
|
||||||
if(define_node.get_type()==ast_identifier && value_node.get_type()==ast_multi_scalar)
|
|
||||||
{
|
|
||||||
die(value_node.get_line(),"one identifier cannot accept too many values");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if(define_node.get_type()==ast_identifier)
|
if(define_node.get_type()==ast_identifier)
|
||||||
{
|
{
|
||||||
std::string new_name=define_node.get_str();
|
std::string new_name=define_node.get_str();
|
||||||
|
@ -1535,11 +1456,6 @@ void nasal_runtime::multi_assignment(nasal_ast& node,int local_scope_addr)
|
||||||
for(int i=0;i<id_size;++i)
|
for(int i=0;i<id_size;++i)
|
||||||
{
|
{
|
||||||
nasal_ast& tmp_node=multi_call_node.get_children()[i];
|
nasal_ast& tmp_node=multi_call_node.get_children()[i];
|
||||||
if(tmp_node.get_type()!=ast_call && tmp_node.get_type()!=ast_identifier)
|
|
||||||
{
|
|
||||||
die(tmp_node.get_line(),"multi-assignment must use available memory address");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
mem_table.push_back(call_scalar_mem(tmp_node,local_scope_addr));
|
mem_table.push_back(call_scalar_mem(tmp_node,local_scope_addr));
|
||||||
}
|
}
|
||||||
if(value_node.get_type()==ast_multi_scalar)
|
if(value_node.get_type()==ast_multi_scalar)
|
||||||
|
|
Loading…
Reference in New Issue