update
This commit is contained in:
parent
eed77f11f8
commit
4946685da2
|
@ -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);
|
||||
}
|
|
@ -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);
|
||||
},
|
||||
};
|
|
@ -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;
|
||||
};
|
|
@ -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);
|
||||
},
|
||||
};
|
|
@ -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;
|
||||
}
|
||||
};
|
|
@ -0,0 +1,166 @@
|
|||
#ifndef __NASAL_BUILTINFUNC_H__
|
||||
#define __NASAL_BUILTINFUNC_H__
|
||||
|
||||
int append(std::list<std::map<std::string,int> >& local_scope)
|
||||
{
|
||||
int vector_addr=-1,elements_addr=-1;
|
||||
for(std::list<std::map<std::string,int> >::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."<<std::endl;
|
||||
return -1;
|
||||
}
|
||||
for(int i=0;i<nasal_gc.get_scalar(elements_addr).get_vector().get_size();++i)
|
||||
{
|
||||
int data_addr=nasal_gc.get_scalar(elements_addr).get_vector().get_elem(i);
|
||||
if(data_addr<0)
|
||||
return -1;
|
||||
int new_addr=-1;
|
||||
switch(nasal_gc.get_scalar(data_addr).get_type())
|
||||
{
|
||||
case scalar_nil:
|
||||
new_addr=nasal_gc.gc_alloc();
|
||||
nasal_gc.get_scalar(new_addr).set_type(scalar_nil);
|
||||
break;
|
||||
case scalar_number:
|
||||
new_addr=nasal_gc.gc_alloc();
|
||||
nasal_gc.get_scalar(new_addr).set_type(scalar_number);
|
||||
nasal_gc.get_scalar(new_addr).get_number().deep_copy(nasal_gc.get_scalar(data_addr).get_number());
|
||||
break;
|
||||
case scalar_string:
|
||||
new_addr=nasal_gc.gc_alloc();
|
||||
nasal_gc.get_scalar(new_addr).set_type(scalar_string);
|
||||
nasal_gc.get_scalar(new_addr).get_string().deep_copy(nasal_gc.get_scalar(data_addr).get_string());
|
||||
break;
|
||||
case scalar_function:
|
||||
new_addr=nasal_gc.gc_alloc();
|
||||
nasal_gc.get_scalar(new_addr).set_type(scalar_function);
|
||||
nasal_gc.get_scalar(new_addr).get_function().deep_copy(nasal_gc.get_scalar(data_addr).get_function());
|
||||
break;
|
||||
case scalar_vector:
|
||||
case scalar_hash:
|
||||
new_addr=data_addr;
|
||||
nasal_gc.reference_add(new_addr);
|
||||
break;
|
||||
}
|
||||
nasal_gc.get_scalar(vector_addr).get_vector().vec_push(new_addr);
|
||||
}
|
||||
int ret_addr=nasal_gc.gc_alloc();
|
||||
nasal_gc.get_scalar(ret_addr).set_type(scalar_nil);
|
||||
return ret_addr;
|
||||
}
|
||||
|
||||
int setsize(std::list<std::map<std::string,int> >& local_scope)
|
||||
{
|
||||
int vector_addr=-1,size_addr=-1;
|
||||
for(std::list<std::map<std::string,int> >::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."<<std::endl;
|
||||
return -1;
|
||||
}
|
||||
vector_size=nasal_gc.get_scalar(vector_addr).get_vector().get_size();
|
||||
if(nasal_gc.get_scalar(size_addr).get_type()==scalar_string &&
|
||||
!check_numerable_string(nasal_gc.get_scalar(size_addr).get_string().get_string()))
|
||||
{
|
||||
std::cout<<">> [Runtime] __size is not a numerable string."<<std::endl;
|
||||
return -1;
|
||||
}
|
||||
if(nasal_gc.get_scalar(size_addr).get_type()!=scalar_string &&
|
||||
nasal_gc.get_scalar(size_addr).get_type()!=scalar_number)
|
||||
{
|
||||
std::cout<<">> [Runtime] __size must be a number or numerable string."<<std::endl;
|
||||
return -1;
|
||||
}
|
||||
if(nasal_gc.get_scalar(size_addr).get_type()==scalar_string &&
|
||||
check_numerable_string(nasal_gc.get_scalar(size_addr).get_string().get_string()))
|
||||
aim_size=(int)trans_string_to_number(nasal_gc.get_scalar(size_addr).get_string().get_string());
|
||||
else if(nasal_gc.get_scalar(size_addr).get_type()==scalar_number)
|
||||
aim_size=(int)nasal_gc.get_scalar(size_addr).get_number().get_number();
|
||||
if(aim_size<0)
|
||||
{
|
||||
std::cout<<">> [Runtime] __size must be greater than 0."<<std::endl;
|
||||
return -1;
|
||||
}
|
||||
if(vector_size<aim_size)
|
||||
{
|
||||
for(int i=vector_size;i<aim_size;++i)
|
||||
{
|
||||
int new_addr=nasal_gc.gc_alloc();
|
||||
nasal_gc.get_scalar(new_addr).set_type(scalar_nil);
|
||||
nasal_gc.get_scalar(vector_addr).get_vector().vec_push(new_addr);
|
||||
}
|
||||
}
|
||||
else if(vector_size>aim_size)
|
||||
for(int i=aim_size;i<vector_size;++i)
|
||||
{
|
||||
int pop_addr=nasal_gc.get_scalar(vector_addr).get_vector().vec_pop();
|
||||
nasal_gc.reference_delete(pop_addr);
|
||||
}
|
||||
int ret_addr=nasal_gc.gc_alloc();
|
||||
nasal_gc.get_scalar(ret_addr).set_type(scalar_nil);
|
||||
return ret_addr;
|
||||
}
|
||||
|
||||
int print(std::list<std::map<std::string,int> >& local_scope)
|
||||
{
|
||||
int vector_addr=-1;
|
||||
for(std::list<std::map<std::string,int> >::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<nasal_gc.get_scalar(vector_addr).get_vector().get_size();++i)
|
||||
{
|
||||
int data_addr=nasal_gc.get_scalar(vector_addr).get_vector().get_elem(i);
|
||||
if(data_addr<0)
|
||||
return -1;
|
||||
switch(nasal_gc.get_scalar(data_addr).get_type())
|
||||
{
|
||||
case scalar_nil:break;
|
||||
case scalar_number:std::cout<<nasal_gc.get_scalar(data_addr).get_number().get_number();break;
|
||||
case scalar_string:std::cout<<nasal_gc.get_scalar(data_addr).get_string().get_string();break;
|
||||
case scalar_vector:std::cout<<"[...]";break;
|
||||
case scalar_hash: std::cout<<"{...}";break;
|
||||
case scalar_function:std::cout<<"func(...){...}";break;
|
||||
}
|
||||
}
|
||||
int ret_addr=nasal_gc.gc_alloc();
|
||||
nasal_gc.get_scalar(ret_addr).set_type(scalar_nil);
|
||||
return ret_addr;
|
||||
}
|
||||
|
||||
int system_type(std::list<std::map<std::string,int> >& local_scope)
|
||||
{
|
||||
int data=-1;
|
||||
for(std::list<std::map<std::string,int> >::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<<std::endl;
|
||||
int ret_addr=nasal_gc.gc_alloc();
|
||||
nasal_gc.get_scalar(ret_addr).set_type(scalar_nil);
|
||||
return ret_addr;
|
||||
}
|
||||
|
||||
#endif
|
|
@ -4,42 +4,42 @@
|
|||
std::string inline_func_name[nas_lib_func_num]=
|
||||
{
|
||||
//base.nas
|
||||
"nasal_call_inline_push_back",// append
|
||||
"nasal_call_inline_set_size", // setsize
|
||||
"nasal_call_inline_subvec",
|
||||
"nasal_call_inline_contains",
|
||||
"nasal_call_inline_delete",
|
||||
"nasal_call_inline_trans_int",
|
||||
"nasal_call_inline_trans_num",
|
||||
"nasal_call_inline_get_keys",
|
||||
"nasal_call_inline_pop_back",
|
||||
"nasal_call_inline_sizeof",
|
||||
"nasal_call_inline_str_cmp_equal",
|
||||
"nasal_call_inline_cmp",
|
||||
"nasal_call_inline_cpp_sort",
|
||||
"nasal_call_inline_substr",
|
||||
"nasal_call_inline_sprintf",
|
||||
"nasal_call_inline_find_first_occur",
|
||||
"nasal_call_inline_split",
|
||||
"nasal_call_inline_rand",
|
||||
"nasal_call_inline_get_id",
|
||||
"nasal_call_builtin_push_back",// append
|
||||
"nasal_call_builtin_set_size", // setsize
|
||||
"nasal_call_builtin_subvec",
|
||||
"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",
|
||||
//bits.nas
|
||||
"nasal_call_built_in_bitcalc",
|
||||
"nasal_call_built_in_sbitcalc",
|
||||
"nasal_call_built_in_setbit",
|
||||
"nasal_call_built_in_null_string_gen",
|
||||
"nasal_call_builtin_bitcalc",
|
||||
"nasal_call_builtin_sbitcalc",
|
||||
"nasal_call_builtin_setbit",
|
||||
"nasal_call_builtin_null_string_gen",
|
||||
//io.nas
|
||||
"nasal_call_inline_c_std_puts",// print
|
||||
"nasal_call_builtin_c_std_puts",// print
|
||||
//math.nas
|
||||
"nasal_call_inline_sin",
|
||||
"nasal_call_inline_cos",
|
||||
"nasal_call_inline_tan",
|
||||
"nasal_call_inline_pow",
|
||||
"nasal_call_inline_cpp_math_ln",
|
||||
"nasal_call_inline_cpp_math_sqrt",
|
||||
"nasal_call_inline_cpp_atan2",
|
||||
"nasal_call_builtin_sin",
|
||||
"nasal_call_builtin_cos",
|
||||
"nasal_call_builtin_tan",
|
||||
"nasal_call_builtin_pow",
|
||||
"nasal_call_builtin_cpp_math_ln",
|
||||
"nasal_call_builtin_cpp_math_sqrt",
|
||||
"nasal_call_builtin_cpp_atan2",
|
||||
//system.nas
|
||||
"nasal_call_inline_scalar_type"//system.type
|
||||
"nasal_call_builtin_scalar_type"//system.type
|
||||
};
|
||||
|
||||
class nasal_runtime
|
||||
|
@ -3000,166 +3000,14 @@ int nasal_runtime::func_proc(
|
|||
int nasal_runtime::builtin_function(std::list<std::map<std::string,int> >& 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<std::map<std::string,int> >::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."<<std::endl;
|
||||
return -1;
|
||||
}
|
||||
for(int i=0;i<nasal_gc.get_scalar(elements_addr).get_vector().get_size();++i)
|
||||
{
|
||||
int data_addr=nasal_gc.get_scalar(elements_addr).get_vector().get_elem(i);
|
||||
if(data_addr<0)
|
||||
return -1;
|
||||
int new_addr=-1;
|
||||
switch(nasal_gc.get_scalar(data_addr).get_type())
|
||||
{
|
||||
case scalar_nil:
|
||||
new_addr=nasal_gc.gc_alloc();
|
||||
nasal_gc.get_scalar(new_addr).set_type(scalar_nil);
|
||||
break;
|
||||
case scalar_number:
|
||||
new_addr=nasal_gc.gc_alloc();
|
||||
nasal_gc.get_scalar(new_addr).set_type(scalar_number);
|
||||
nasal_gc.get_scalar(new_addr).get_number().deep_copy(nasal_gc.get_scalar(data_addr).get_number());
|
||||
break;
|
||||
case scalar_string:
|
||||
new_addr=nasal_gc.gc_alloc();
|
||||
nasal_gc.get_scalar(new_addr).set_type(scalar_string);
|
||||
nasal_gc.get_scalar(new_addr).get_string().deep_copy(nasal_gc.get_scalar(data_addr).get_string());
|
||||
break;
|
||||
case scalar_function:
|
||||
new_addr=nasal_gc.gc_alloc();
|
||||
nasal_gc.get_scalar(new_addr).set_type(scalar_function);
|
||||
nasal_gc.get_scalar(new_addr).get_function().deep_copy(nasal_gc.get_scalar(data_addr).get_function());
|
||||
break;
|
||||
case scalar_vector:
|
||||
case scalar_hash:
|
||||
new_addr=data_addr;
|
||||
nasal_gc.reference_add(new_addr);
|
||||
break;
|
||||
}
|
||||
nasal_gc.get_scalar(vector_addr).get_vector().vec_push(new_addr);
|
||||
}
|
||||
ret_addr=nasal_gc.gc_alloc();
|
||||
nasal_gc.get_scalar(ret_addr).set_type(scalar_nil);
|
||||
}
|
||||
else if(func_name=="nasal_call_inline_set_size")
|
||||
{
|
||||
// setsize
|
||||
int vector_addr=-1;
|
||||
int size_addr=-1;
|
||||
for(std::list<std::map<std::string,int> >::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."<<std::endl;
|
||||
return -1;
|
||||
}
|
||||
vector_size=nasal_gc.get_scalar(vector_addr).get_vector().get_size();
|
||||
if(nasal_gc.get_scalar(size_addr).get_type()==scalar_string &&
|
||||
!check_numerable_string(nasal_gc.get_scalar(size_addr).get_string().get_string()))
|
||||
{
|
||||
std::cout<<">> [Runtime] __size is not a numerable string."<<std::endl;
|
||||
return -1;
|
||||
}
|
||||
if(nasal_gc.get_scalar(size_addr).get_type()!=scalar_string &&
|
||||
nasal_gc.get_scalar(size_addr).get_type()!=scalar_number)
|
||||
{
|
||||
std::cout<<">> [Runtime] __size must be a number or numerable string."<<std::endl;
|
||||
return -1;
|
||||
}
|
||||
if(nasal_gc.get_scalar(size_addr).get_type()==scalar_string &&
|
||||
check_numerable_string(nasal_gc.get_scalar(size_addr).get_string().get_string()))
|
||||
aim_size=(int)trans_string_to_number(nasal_gc.get_scalar(size_addr).get_string().get_string());
|
||||
else if(nasal_gc.get_scalar(size_addr).get_type()==scalar_number)
|
||||
aim_size=(int)nasal_gc.get_scalar(size_addr).get_number().get_number();
|
||||
if(aim_size<0)
|
||||
{
|
||||
std::cout<<">> [Runtime] __size must be greater than 0."<<std::endl;
|
||||
return -1;
|
||||
}
|
||||
if(vector_size<aim_size)
|
||||
{
|
||||
for(int i=vector_size;i<aim_size;++i)
|
||||
{
|
||||
int new_addr=nasal_gc.gc_alloc();
|
||||
nasal_gc.get_scalar(new_addr).set_type(scalar_nil);
|
||||
nasal_gc.get_scalar(vector_addr).get_vector().vec_push(new_addr);
|
||||
}
|
||||
}
|
||||
else if(vector_size>aim_size)
|
||||
for(int i=aim_size;i<vector_size;++i)
|
||||
{
|
||||
int pop_addr=nasal_gc.get_scalar(vector_addr).get_vector().vec_pop();
|
||||
nasal_gc.reference_delete(pop_addr);
|
||||
}
|
||||
ret_addr=nasal_gc.gc_alloc();
|
||||
nasal_gc.get_scalar(ret_addr).set_type(scalar_nil);
|
||||
}
|
||||
else if(func_name=="nasal_call_inline_c_std_puts")
|
||||
{
|
||||
// print
|
||||
int vector_addr=-1;
|
||||
for(std::list<std::map<std::string,int> >::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<nasal_gc.get_scalar(vector_addr).get_vector().get_size();++i)
|
||||
{
|
||||
int data_addr=nasal_gc.get_scalar(vector_addr).get_vector().get_elem(i);
|
||||
if(data_addr<0)
|
||||
return -1;
|
||||
switch(nasal_gc.get_scalar(data_addr).get_type())
|
||||
{
|
||||
case scalar_nil:break;
|
||||
case scalar_number:std::cout<<nasal_gc.get_scalar(data_addr).get_number().get_number();break;
|
||||
case scalar_string:std::cout<<nasal_gc.get_scalar(data_addr).get_string().get_string();break;
|
||||
case scalar_vector:std::cout<<"[...]";break;
|
||||
case scalar_hash: std::cout<<"{...}";break;
|
||||
case scalar_function:std::cout<<"func(...){...}";break;
|
||||
}
|
||||
}
|
||||
ret_addr=nasal_gc.gc_alloc();
|
||||
nasal_gc.get_scalar(ret_addr).set_type(scalar_nil);
|
||||
}
|
||||
else if(func_name=="nasal_call_inline_scalar_type")
|
||||
{
|
||||
// system.type
|
||||
int data=-1;
|
||||
for(std::list<std::map<std::string,int> >::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<<std::endl;
|
||||
ret_addr=nasal_gc.gc_alloc();
|
||||
nasal_gc.get_scalar(ret_addr).set_type(scalar_nil);
|
||||
}
|
||||
if(func_name=="nasal_call_builtin_push_back")
|
||||
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_c_std_puts")
|
||||
ret_addr=print(local_scope);
|
||||
else if(func_name=="nasal_call_builtin_scalar_type")
|
||||
ret_addr=system_type(local_scope);
|
||||
return ret_addr;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue