From 4946685da2d0fa939c6b5398f148e00a08148655 Mon Sep 17 00:00:00 2001 From: Valk Richard Li <48872266+ValKmjolnir@users.noreply.github.com> Date: Mon, 11 May 2020 01:40:44 -0700 Subject: [PATCH] update --- version2.0/lib/base.nas | 38 +++--- version2.0/lib/bits.nas | 8 +- version2.0/lib/io.nas | 18 +-- version2.0/lib/math.nas | 14 +- version2.0/lib/system.nas | 2 +- version2.0/nasal_builtinfunc.h | 166 +++++++++++++++++++++++ version2.0/nasal_runtime.h | 232 ++++++--------------------------- 7 files changed, 246 insertions(+), 232 deletions(-) create mode 100644 version2.0/nasal_builtinfunc.h diff --git a/version2.0/lib/base.nas b/version2.0/lib/base.nas index cd39444..f99e814 100644 --- a/version2.0/lib/base.nas +++ b/version2.0/lib/base.nas @@ -10,7 +10,7 @@ # Appends the remaining arguments to the end of the vector. var append=func(vector,elements...) { - nasal_call_inline_push_back(vector,elements); + nasal_call_builtin_push_back(vector,elements); return nil; } @@ -21,7 +21,7 @@ var append=func(vector,elements...) # If it is smaller, it is padded with nil entries.Returns the vector operated upon. var setsize=func(vector,__size) { - nasal_call_inline_set_size(vector,__size); + nasal_call_builtin_set_size(vector,__size); return nil; } @@ -31,7 +31,7 @@ var setsize=func(vector,__size) # and the optional third argument indicates a length (the default is to the end of the vector). var subvec=func(vector,start,length=nil) { - return nasal_call_inline_subvec(vector,start,length); + return nasal_call_builtin_subvec(vector,start,length); } # contains @@ -39,7 +39,7 @@ var subvec=func(vector,start,length=nil) # Returns 1 if the hash contains the scalar as a key, 0 if not. var contains=func(hash,key) { - return nasal_call_inline_contains(hash,key); + return nasal_call_builtin_contains(hash,key); } # delete @@ -49,7 +49,7 @@ var contains=func(hash,key) # but this variant potentially frees storage by deleting the reference to the key and by shrinking the hash. var delete=func(hash,key) { - nasal_call_inline_delete(hash,key); + nasal_call_builtin_delete(hash,key); return; } @@ -58,28 +58,28 @@ var delete=func(hash,key) # Truncates towards zero, not negative infinity (i.e. it's implemented in C as a double tointeger typecast). var int=func(value) { - return nasal_call_inline_trans_int(value); + return nasal_call_builtin_trans_int(value); } # num # Returns the numeric value of the single argument, or nil if none exists. var num=func(value) { - return nasal_call_inline_trans_num(value); + return nasal_call_builtin_trans_num(value); } # keys # Returns a vector containing the list of keys found in the single hash argument. var keys=func(hash) { - return nasal_call_inline_get_keys(hash); + return nasal_call_builtin_get_keys(hash); } # pop # Removes and returns the last element of the single vector argument. var pop=func(vector) { - return nasal_call_inline_pop_back(vector); + return nasal_call_builtin_pop_back(vector); } # size @@ -90,7 +90,7 @@ var pop=func(vector) # Returns nil for number and nil arguments. var size=func(object) { - return nasal_call_inline_sizeof(object); + return nasal_call_builtin_sizeof(object); } # streq @@ -100,14 +100,14 @@ var size=func(object) # This is rarely required in typical code. var streq=func(__a,__b) { - return nasal_call_inline_str_cmp_equal(__a,__b); + return nasal_call_builtin_str_cmp_equal(__a,__b); } # cmp # Compares two strings, returning -1 if a is less than b, 0 if theyare identical, and 1 if a is greater than b. var cmp=func(__a,__b) { - return nasal_call_inline_cmp(__a,__b); + return nasal_call_builtin_cmp(__a,__b); } # sort @@ -117,7 +117,7 @@ var cmp=func(__a,__b) # the sort is stable; "equal" elements in the output vector will appear in the same relative order as they do in the input. var sort=func(vector,function) { - nasal_call_inline_cpp_sort(vector,function); + nasal_call_builtin_cpp_sort(vector,function); return; } @@ -128,28 +128,28 @@ var sort=func(vector,function) # Example: substr("abcde", 1, 3) returns "bcd". var substr=func(__string,start,length=nil) { - return nasal_call_inline_substr(__string,start,length); + return nasal_call_builtin_substr(__string,start,length); } # sprintf # Creates and returns a string formatted as per ANSI C sprintf(). var sprintf=func(__format,var_args...) { - return nasal_call_inline_sprintf(__format,var_args); + return nasal_call_builtin_sprintf(__format,var_args); } # find # Finds and returns the index of the first occurence of the string needle in the string haystack, or -1 if no such occurence was found. var find=func(needle,haystack) { - return nasal_call_inline_find_first_occur(needle,haystack); + return nasal_call_builtin_find_first_occur(needle,haystack); } # split # Splits the input string into a vector of substrings bounded by occurences of the delimeter substring. var split=func(delimeter,__string) { - return nasal_call_inline_split(delimeter,__string); + return nasal_call_builtin_split(delimeter,__string); } # rand @@ -159,7 +159,7 @@ var split=func(delimeter,__string) # the result should have a full double-precision number's worth of randomness even on systems with a 15 bit rand(). var rand=func(seed=nil) { - return nasal_call_inline_rand(seed); + return nasal_call_builtin_rand(seed); } # id @@ -168,5 +168,5 @@ var rand=func(seed=nil) # Numbers don't have id's and will cause a runtime error if passed to id(). var id=func(thing) { - return nasal_call_inline_get_id(thing); + return nasal_call_builtin_get_id(thing); } \ No newline at end of file diff --git a/version2.0/lib/bits.nas b/version2.0/lib/bits.nas index 642cb4e..d5b769f 100644 --- a/version2.0/lib/bits.nas +++ b/version2.0/lib/bits.nas @@ -14,23 +14,23 @@ var bits= # The last bit is the low bit of the last byte in the string. fld:func(__string,startbit,length) { - return nasal_call_built_in_bitcalc(__string,startbit,length); + return nasal_call_builtin_bitcalc(__string,startbit,length); }, # As bits.fld(), but interprets the result as a 2's complement signed value. sfld:func(__string,startbit,length) { - return nasal_call_built_in_sbitcalc(__string,startbit,length); + return nasal_call_builtin_sbitcalc(__string,startbit,length); }, # Sets the specified value into the bit string at the specified position. # The string must be mutable: either the result of a runtime concatenation (the ~ operator) or a call to bits.buf()(see below). # Attempts to modify immutable strings (e.g. compile time constants) will produce a runtime error. setfld:func(__string,startbit,length,value) { - return nasal_call_built_in_setbit(__string,startbit,length,value); + return nasal_call_builtin_setbit(__string,startbit,length,value); }, # Returns a zero-filled mutable string of the specified length. buf:func(length) { - return nasal_call_built_in_null_string_gen(length); + return nasal_call_builtin_null_string_gen(length); }, }; \ No newline at end of file diff --git a/version2.0/lib/io.nas b/version2.0/lib/io.nas index 789ea35..29c6093 100644 --- a/version2.0/lib/io.nas +++ b/version2.0/lib/io.nas @@ -11,12 +11,12 @@ var io= # Failures are thrown as runtime errors as per die(). open:func(filename,mode="r") { - return nasal_call_inline_c_fopen(filename,mode); + return nasal_call_builtin_c_fopen(filename,mode); }, # Closes the specified file as per ANSI fclose(). close:func(filehandle) { - nasal_call_inline_c_fclose(filehandle); + nasal_call_builtin_c_fclose(filehandle); return; }, # Attempts to read length bytes from the filehandle into the beginning of the mutable string buf. @@ -24,14 +24,14 @@ var io= # Returns the number of bytes successfully read. read:func(filehandle,buf,length) { - return nasal_call_inline_c_read(filehandle,buf,length); + return nasal_call_builtin_c_read(filehandle,buf,length); }, # Attempts to write the entirety of the specified string to the filehandle. # Failures are thrown as runtime errors as per die(). # Returns the number of bytes successfully written. write:func(filehandle,str) { - return nasal_call_inline_c_write(filehandle,str); + return nasal_call_builtin_c_write(filehandle,str); }, # As ANSI fseek(). # Attempts to seek to the specified position based on the whence value @@ -41,13 +41,13 @@ var io= SEEK_END:3, seek:func(filehandle,position,whence) { - nasal_call_inline_c_seek(filehandle,position,whence); + nasal_call_builtin_c_seek(filehandle,position,whence); return; }, # Returns the current seek position of the filehandle. tell:func(filehandle) { - return nasal_call_inline_c_tell(filehandle); + return nasal_call_builtin_c_tell(filehandle); }, # Reads and returns a single text line from the filehandle. # Interprets both "\n" and "\r\n" as end of line markers, @@ -55,7 +55,7 @@ var io= # End offile or error is signaled by returning nil. readln:func(filehandle) { - return nasal_call_inline_builtin_c_getline(filehandle); + return nasal_call_builtin_builtin_c_getline(filehandle); }, # Calls unix or win32 stat() on the specified file name and # returns a seven element array whose contents are, @@ -63,12 +63,12 @@ var io= # Errors are signaled as exceptions as per die(). stat:func(filename) { - return nasal_call_inline_builtin_stat(filename); + return nasal_call_builtin_builtin_stat(filename); }, }; var print=func(dyn...) { - nasal_call_inline_c_std_puts(dyn); + nasal_call_builtin_c_std_puts(dyn); return nil; }; \ No newline at end of file diff --git a/version2.0/lib/math.nas b/version2.0/lib/math.nas index d354613..0c4cb90 100644 --- a/version2.0/lib/math.nas +++ b/version2.0/lib/math.nas @@ -13,37 +13,37 @@ var math= # Returns the sine of the single argument sin:func(x) { - return nasal_call_inline_sin(x); + return nasal_call_builtin_sin(x); }, # Returns the cosine of the single argument cos:func(x) { - return nasal_call_inline_cos(x); + return nasal_call_builtin_cos(x); }, # you know what the f*ck this is tan:func(x) { - return nasal_call_inline_tan(x); + return nasal_call_builtin_tan(x); }, # Returns e (Euler's constant) raised to the power specified by the single argument exp:func(x) { - return nasal_call_inline_pow(me.e,x); + return nasal_call_builtin_pow(me.e,x); }, # Returns the natural logarithm of the single argument. ln:func(x) { - return nasal_call_inline_cpp_math_ln(x); + return nasal_call_builtin_cpp_math_ln(x); }, # Returns the square root of the single argument. sqrt:func(x) { - return nasal_call_inline_cpp_math_sqrt(x); + return nasal_call_builtin_cpp_math_sqrt(x); }, # Returns the arctangent of y/x, with the correct sign for the quadrant. # Wraps the ANSI C function of the same name. atan2:func(x,y) { - return nasal_call_inline_cpp_atan2(x,y); + return nasal_call_builtin_cpp_atan2(x,y); }, }; \ No newline at end of file diff --git a/version2.0/lib/system.nas b/version2.0/lib/system.nas index 84d7b16..9816478 100644 --- a/version2.0/lib/system.nas +++ b/version2.0/lib/system.nas @@ -3,7 +3,7 @@ var system= # print the type of thing on the screen type:func(thing) { - nasal_call_inline_scalar_type(thing); + nasal_call_builtin_scalar_type(thing); return; } }; \ No newline at end of file diff --git a/version2.0/nasal_builtinfunc.h b/version2.0/nasal_builtinfunc.h new file mode 100644 index 0000000..aa49111 --- /dev/null +++ b/version2.0/nasal_builtinfunc.h @@ -0,0 +1,166 @@ +#ifndef __NASAL_BUILTINFUNC_H__ +#define __NASAL_BUILTINFUNC_H__ + +int append(std::list >& local_scope) +{ + int vector_addr=-1,elements_addr=-1; + 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("elements")!=i->end()) + elements_addr=(*i)["elements"]; + } + if(vector_addr<0 || elements_addr<0) + return -1; + if(nasal_gc.get_scalar(vector_addr).get_type()!=scalar_vector) + { + std::cout<<">> [Runtime] append gets a value that is not a vector."< >& local_scope) +{ + int vector_addr=-1,size_addr=-1; + 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("__size")!=i->end()) + size_addr=(*i)["__size"]; + } + if(vector_addr<0 || size_addr<0) + return -1; + int vector_size=-1; + int aim_size=-1; + if(nasal_gc.get_scalar(vector_addr).get_type()!=scalar_vector) + { + std::cout<<">> [Runtime] setsize gets a variable that is not a vector."<> [Runtime] __size is not a numerable string."<> [Runtime] __size must be a number or numerable string."<> [Runtime] __size must be greater than 0."<aim_size) + for(int i=aim_size;i >& local_scope) +{ + int vector_addr=-1; + for(std::list >::iterator i=local_scope.begin();i!=local_scope.end();++i) + if(i->find("dyn")!=i->end()) + vector_addr=(*i)["dyn"]; + if(vector_addr<0) + return -1; + for(int i=0;i >& local_scope) +{ + int data=-1; + for(std::list >::iterator i=local_scope.begin();i!=local_scope.end();++i) + if(i->find("thing")!=i->end()) + data=(*i)["thing"]; + if(data<0) + return -1; + print_scalar_type(nasal_gc.get_scalar(data).get_type()); + std::cout< >& local_scope,std::string func_name) { int ret_addr=-1; - if(func_name=="nasal_call_inline_push_back") - { - // append - int vector_addr=-1; - int elements_addr=-1; - 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("elements")!=i->end()) - elements_addr=(*i)["elements"]; - } - if(vector_addr<0 || elements_addr<0) - return -1; - if(nasal_gc.get_scalar(vector_addr).get_type()!=scalar_vector) - { - std::cout<<">> [Runtime] append gets a value that is not a vector."< >::iterator i=local_scope.begin();i!=local_scope.end();++i) - { - if(i->find("vector")!=i->end()) - vector_addr=(*i)["vector"]; - if(i->find("__size")!=i->end()) - size_addr=(*i)["__size"]; - } - if(vector_addr<0 || size_addr<0) - return -1; - int vector_size=-1; - int aim_size=-1; - if(nasal_gc.get_scalar(vector_addr).get_type()!=scalar_vector) - { - std::cout<<">> [Runtime] setsize gets a variable that is not a vector."<> [Runtime] __size is not a numerable string."<> [Runtime] __size must be a number or numerable string."<> [Runtime] __size must be greater than 0."<aim_size) - for(int i=aim_size;i >::iterator i=local_scope.begin();i!=local_scope.end();++i) - if(i->find("dyn")!=i->end()) - vector_addr=(*i)["dyn"]; - if(vector_addr<0) - return -1; - for(int i=0;i >::iterator i=local_scope.begin();i!=local_scope.end();++i) - if(i->find("thing")!=i->end()) - data=(*i)["thing"]; - if(data<0) - return -1; - print_scalar_type(nasal_gc.get_scalar(data).get_type()); - std::cout<