From 54c855e17e421dd838132a840285a58d6520e688 Mon Sep 17 00:00:00 2001 From: Valk Richard Li <48872266+ValKmjolnir@users.noreply.github.com> Date: Mon, 18 May 2020 01:46:25 -0700 Subject: [PATCH] update --- version2.0/lib/math.nas | 2 +- version2.0/nasal_builtinfunc.h | 201 +++++++++++++++++++++++++++++++++ version2.0/nasal_runtime.h | 37 +++++- 3 files changed, 238 insertions(+), 2 deletions(-) diff --git a/version2.0/lib/math.nas b/version2.0/lib/math.nas index 0c4cb90..1bbafa4 100644 --- a/version2.0/lib/math.nas +++ b/version2.0/lib/math.nas @@ -28,7 +28,7 @@ var math= # Returns e (Euler's constant) raised to the power specified by the single argument exp:func(x) { - return nasal_call_builtin_pow(me.e,x); + return nasal_call_builtin_exp(x); }, # Returns the natural logarithm of the single argument. ln:func(x) diff --git a/version2.0/nasal_builtinfunc.h b/version2.0/nasal_builtinfunc.h index aa49111..263b933 100644 --- a/version2.0/nasal_builtinfunc.h +++ b/version2.0/nasal_builtinfunc.h @@ -120,6 +120,141 @@ int setsize(std::list >& local_scope) return ret_addr; } +int subvec(std::list >& local_scope) +{ + int vector_addr=-1,start=-1,length=-1,type=-1; + int begin_iter=0,len_iter=0; + for(std::list >::iterator i=local_scope.begin();i!=local_scope.end();++i) + { + if(i->find("vector")!=i->end()) + vector_addr=(*i)["vector"]; + if(i->find("start")!=i->end()) + start=(*i)["start"]; + if(i->find("length")!=i->end()) + length=(*i)["length"]; + } + if(vector_addr<0 || start<0 || length<0) + return -1; + if(nasal_gc.get_scalar(vector_addr).get_type()!=scalar_vector) + { + std::cout<<">> subvec gets a value that is not a vector."<> [Runtime] \'start\' is not a number or numerable string."<> [Runtime] \'start\' is not a numerable string."<> [Runtime] \'length\' is not a nil type,number or numerable string."<> [Runtime] \'length\' is not a numerable string."<> [Runtime] subvec out of memory boundary."<> [Runtime] subvec out of memory boundary."< >& local_scope) { int vector_addr=-1; @@ -163,4 +298,70 @@ int system_type(std::list >& local_scope) return ret_addr; } +int nas_trigfunc(std::list >& local_scope,int func_type) +{ + int data=-1; + double num=0; + int type=-1; + for(std::list >::iterator i=local_scope.begin();i!=local_scope.end();++i) + if(i->find("x")!=i->end()) + data=(*i)["x"]; + if(data<0) + return -1; + type=nasal_gc.get_scalar(data).get_type(); + if(type!=scalar_number && type!=scalar_string) + { + std::cout<<">> [Runtime] x must be a number or numerable string."<> [Runtime] x is not a numerable string."< >& local_scope) +{ + int data=-1; + double num=0; + int type=-1; + for(std::list >::iterator i=local_scope.begin();i!=local_scope.end();++i) + if(i->find("x")!=i->end()) + data=(*i)["x"]; + if(data<0) + return -1; + type=nasal_gc.get_scalar(data).get_type(); + if(type!=scalar_number && type!=scalar_string) + { + std::cout<<">> [Runtime] x must be a number or numerable string."<> [Runtime] x is not a numerable string."< >& local ret_addr=append(local_scope); else if(func_name=="nasal_call_builtin_set_size") ret_addr=setsize(local_scope); + else if(func_name=="nasal_call_builtin_subvec") + ret_addr=subvec(local_scope); else if(func_name=="nasal_call_builtin_c_std_puts") ret_addr=print(local_scope); else if(func_name=="nasal_call_builtin_scalar_type") ret_addr=system_type(local_scope); + else if(func_name=="nasal_call_builtin_sin") + ret_addr=nas_trigfunc(local_scope,0); + else if(func_name=="nasal_call_builtin_cos") + ret_addr=nas_trigfunc(local_scope,1); + else if(func_name=="nasal_call_builtin_tan") + ret_addr=nas_trigfunc(local_scope,2); + else if(func_name=="nasal_call_builtin_exp") + ret_addr=nas_exp(local_scope); + // "nasal_call_builtin_contains", + // "nasal_call_builtin_delete", + // "nasal_call_builtin_trans_int", + // "nasal_call_builtin_trans_num", + // "nasal_call_builtin_get_keys", + // "nasal_call_builtin_pop_back", + // "nasal_call_builtin_sizeof", + // "nasal_call_builtin_str_cmp_equal", + // "nasal_call_builtin_cmp", + // "nasal_call_builtin_cpp_sort", + // "nasal_call_builtin_substr", + // "nasal_call_builtin_sprintf", + // "nasal_call_builtin_find_first_occur", + // "nasal_call_builtin_split", + // "nasal_call_builtin_rand", + // "nasal_call_builtin_get_id", + + // "nasal_call_builtin_bitcalc", + // "nasal_call_builtin_sbitcalc", + // "nasal_call_builtin_setbit", + // "nasal_call_builtin_null_string_gen", + + // "nasal_call_builtin_cpp_math_ln", + // "nasal_call_builtin_cpp_math_sqrt", + // "nasal_call_builtin_cpp_atan2", return ret_addr; }