update
This commit is contained in:
parent
8dc04bf95d
commit
c0f58cc2b1
|
@ -10,9 +10,8 @@
|
||||||
# Appends the remaining arguments to the end of the vector.
|
# Appends the remaining arguments to the end of the vector.
|
||||||
var append=func(vector,elements...)
|
var append=func(vector,elements...)
|
||||||
{
|
{
|
||||||
var call_inline_push_back=func(vector,elements){};
|
nasal_call_inline_push_back(vector,elements);
|
||||||
call_inline_push_back(vector,elements);
|
return nil;
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# setsize
|
# setsize
|
||||||
|
@ -22,9 +21,8 @@ var append=func(vector,elements...)
|
||||||
# If it is smaller, it is padded with nil entries.Returns the vector operated upon.
|
# If it is smaller, it is padded with nil entries.Returns the vector operated upon.
|
||||||
var setsize=func(vector,__size)
|
var setsize=func(vector,__size)
|
||||||
{
|
{
|
||||||
var call_inline_push_null=func(vector,__size){};
|
nasal_call_inline_push_null(vector,__size);
|
||||||
call_inline_push_null(vector,__size);
|
return nil;
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# subvec
|
# subvec
|
||||||
|
@ -33,8 +31,7 @@ var setsize=func(vector,__size)
|
||||||
# and the optional third argument indicates a length (the default is to the end of the vector).
|
# and the optional third argument indicates a length (the default is to the end of the vector).
|
||||||
var subvec=func(vector,start,length=nil)
|
var subvec=func(vector,start,length=nil)
|
||||||
{
|
{
|
||||||
var call_inline_subvec=func(vector,start,length=nil){};
|
return nasal_call_inline_subvec(vector,start,length);
|
||||||
return call_inline_subvec(vector,start,length);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# contains
|
# contains
|
||||||
|
@ -42,8 +39,7 @@ var subvec=func(vector,start,length=nil)
|
||||||
# Returns 1 if the hash contains the scalar as a key, 0 if not.
|
# Returns 1 if the hash contains the scalar as a key, 0 if not.
|
||||||
var contains=func(hash,key)
|
var contains=func(hash,key)
|
||||||
{
|
{
|
||||||
var call_inline_contains=func(hash,key){};
|
return nasal_call_inline_contains(hash,key);
|
||||||
return call_inline_contains(hash,key);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# delete
|
# delete
|
||||||
|
@ -53,8 +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.
|
# but this variant potentially frees storage by deleting the reference to the key and by shrinking the hash.
|
||||||
var delete=func(hash,key)
|
var delete=func(hash,key)
|
||||||
{
|
{
|
||||||
var call_inline_delete=func(hash,key){};
|
nasal_call_inline_delete(hash,key);
|
||||||
call_inline_delete(hash,key);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -63,35 +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).
|
# Truncates towards zero, not negative infinity (i.e. it's implemented in C as a double tointeger typecast).
|
||||||
var int=func(value)
|
var int=func(value)
|
||||||
{
|
{
|
||||||
var inline_trans_int=func(value){};
|
return nasal_call_inline_trans_int(value);
|
||||||
return inline_trans_int(value);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# num
|
# num
|
||||||
# Returns the numeric value of the single argument, or nil if none exists.
|
# Returns the numeric value of the single argument, or nil if none exists.
|
||||||
var num=func(value)
|
var num=func(value)
|
||||||
{
|
{
|
||||||
var inline_trans_num=func(value){};
|
return nasal_call_inline_trans_num(value);
|
||||||
return inline_trans_num(value);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# keys
|
# keys
|
||||||
# Returns a vector containing the list of keys found in the single hash argument.
|
# Returns a vector containing the list of keys found in the single hash argument.
|
||||||
var keys=func(hash)
|
var keys=func(hash)
|
||||||
{
|
{
|
||||||
var inline_get_keys=func(hash){};
|
return nasal_call_inline_get_keys(hash);
|
||||||
return inline_get_keys(hash);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# pop
|
# pop
|
||||||
# Removes and returns the last element of the single vector argument.
|
# Removes and returns the last element of the single vector argument.
|
||||||
var pop=func(vector)
|
var pop=func(vector)
|
||||||
{
|
{
|
||||||
var inline_get_back=func(vector){};
|
return nasal_call_inline_pop_back(vector);
|
||||||
var inline_pop_back=func(vector){};
|
|
||||||
var ret=inline_get_back(vector);
|
|
||||||
inline_pop_back(vector);
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# size
|
# size
|
||||||
|
@ -102,8 +90,7 @@ var pop=func(vector)
|
||||||
# Returns nil for number and nil arguments.
|
# Returns nil for number and nil arguments.
|
||||||
var size=func(object)
|
var size=func(object)
|
||||||
{
|
{
|
||||||
var call_inline_sizeof=func(object){};
|
return nasal_call_inline_sizeof(object);
|
||||||
return call_inline_sizeof(object);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# streq
|
# streq
|
||||||
|
@ -113,16 +100,14 @@ var size=func(object)
|
||||||
# This is rarely required in typical code.
|
# This is rarely required in typical code.
|
||||||
var streq=func(__a,__b)
|
var streq=func(__a,__b)
|
||||||
{
|
{
|
||||||
var inline_str_cmp_equal=func(str1,str2){};
|
return nasal_call_inline_str_cmp_equal(__a,__b);
|
||||||
return inline_str_cmp_equal(__a,__b);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# cmp
|
# cmp
|
||||||
# Compares two strings, returning -1 if a is less than b, 0 if theyare identical, and 1 if a is greater than b.
|
# 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)
|
var cmp=func(__a,__b)
|
||||||
{
|
{
|
||||||
var inline_cmp=func(var1,var2){};
|
return nasal_call_inline_cmp(__a,__b);
|
||||||
return inline_cmp(__a,__b);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# sort
|
# sort
|
||||||
|
@ -132,8 +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.
|
# 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)
|
var sort=func(vector,function)
|
||||||
{
|
{
|
||||||
var call_cpp_sort=func(vector,function){};
|
nasal_call_inline_cpp_sort(vector,function);
|
||||||
call_cpp_sort(vector,function);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -144,32 +128,28 @@ var sort=func(vector,function)
|
||||||
# Example: substr("abcde", 1, 3) returns "bcd".
|
# Example: substr("abcde", 1, 3) returns "bcd".
|
||||||
var substr=func(__string,start,length=nil)
|
var substr=func(__string,start,length=nil)
|
||||||
{
|
{
|
||||||
var call_inline_substr=func(__string,start,length){};
|
return nasal_call_inline_substr(__string,start,length);
|
||||||
return call_inline_substr(__string,start,length);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# sprintf
|
# sprintf
|
||||||
# Creates and returns a string formatted as per ANSI C sprintf().
|
# Creates and returns a string formatted as per ANSI C sprintf().
|
||||||
var sprintf=func(__format,var_args...)
|
var sprintf=func(__format,var_args...)
|
||||||
{
|
{
|
||||||
var call_inline_sprintf=func(__format,var_args){};
|
return nasal_call_inline_sprintf(__format,var_args);
|
||||||
return call_inline_sprintf(__format,var_args);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# find
|
# 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.
|
# 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)
|
var find=func(needle,haystack)
|
||||||
{
|
{
|
||||||
var inline_find_first_occur=func(needle,haystack){};
|
return nasal_call_inline_find_first_occur(needle,haystack);
|
||||||
return inline_find_first_occur(needle,haystack);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# split
|
# split
|
||||||
# Splits the input string into a vector of substrings bounded by occurences of the delimeter substring.
|
# Splits the input string into a vector of substrings bounded by occurences of the delimeter substring.
|
||||||
var split=func(delimeter,__string)
|
var split=func(delimeter,__string)
|
||||||
{
|
{
|
||||||
var inline_split=func(delimeter,__string){};
|
return nasal_call_inline_split(delimeter,__string);
|
||||||
return inline_split(delimeter,__string);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# rand
|
# rand
|
||||||
|
@ -179,8 +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().
|
# 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)
|
var rand=func(seed=nil)
|
||||||
{
|
{
|
||||||
var inline_rand=func(seed){};
|
return nasal_call_inline_rand(seed);
|
||||||
return inline_rand(seed);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# id
|
# id
|
||||||
|
@ -189,6 +168,5 @@ var rand=func(seed=nil)
|
||||||
# Numbers don't have id's and will cause a runtime error if passed to id().
|
# Numbers don't have id's and will cause a runtime error if passed to id().
|
||||||
var id=func(thing)
|
var id=func(thing)
|
||||||
{
|
{
|
||||||
var inline_getid=func(thing){};
|
return nasal_call_inline_get_id(thing);
|
||||||
return inline_getid(thing);
|
|
||||||
}
|
}
|
|
@ -14,27 +14,23 @@ var bits=
|
||||||
# The last bit is the low bit of the last byte in the string.
|
# The last bit is the low bit of the last byte in the string.
|
||||||
fld:func(__string,startbit,length)
|
fld:func(__string,startbit,length)
|
||||||
{
|
{
|
||||||
var call_built_in_bitcalc=func(__str,__start,__len){};
|
return nasal_call_built_in_bitcalc(__string,startbit,length);
|
||||||
return call_built_in_bitcalc(__string,startbit,length);
|
|
||||||
},
|
},
|
||||||
# As bits.fld(), but interprets the result as a 2's complement signed value.
|
# As bits.fld(), but interprets the result as a 2's complement signed value.
|
||||||
sfld:func(__string,startbit,length)
|
sfld:func(__string,startbit,length)
|
||||||
{
|
{
|
||||||
var call_built_in_sbitcalc=func(__str,__start,__len){};
|
return nasal_call_built_in_sbitcalc(__string,startbit,length);
|
||||||
return call_built_in_sbitcalc(__string,startbit,length);
|
|
||||||
},
|
},
|
||||||
# Sets the specified value into the bit string at the specified position.
|
# 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).
|
# 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.
|
# Attempts to modify immutable strings (e.g. compile time constants) will produce a runtime error.
|
||||||
setfld:func(__string,startbit,length,value)
|
setfld:func(__string,startbit,length,value)
|
||||||
{
|
{
|
||||||
var call_built_in_setbit=func(__str,__start,__len,__val){};
|
return nasal_call_built_in_setbit(__string,startbit,length,value);
|
||||||
return call_built_in_setbit(__string,startbit,length,value);
|
|
||||||
},
|
},
|
||||||
# Returns a zero-filled mutable string of the specified length.
|
# Returns a zero-filled mutable string of the specified length.
|
||||||
buf:func(length)
|
buf:func(length)
|
||||||
{
|
{
|
||||||
var call_built_in_null_string_gen=func(__len){};
|
return nasal_call_built_in_null_string_gen(length);
|
||||||
return call_built_in_null_string_gen(length);
|
|
||||||
},
|
},
|
||||||
};
|
};
|
|
@ -11,14 +11,12 @@ var io=
|
||||||
# Failures are thrown as runtime errors as per die().
|
# Failures are thrown as runtime errors as per die().
|
||||||
open:func(filename,mode="r")
|
open:func(filename,mode="r")
|
||||||
{
|
{
|
||||||
var call_c_fopen=func(__file,__mode){};
|
return nasal_call_inline_c_fopen(filename,mode);
|
||||||
return call_c_fopen(filename,mode);
|
|
||||||
},
|
},
|
||||||
# Closes the specified file as per ANSI fclose().
|
# Closes the specified file as per ANSI fclose().
|
||||||
close:func(filehandle)
|
close:func(filehandle)
|
||||||
{
|
{
|
||||||
var call_c_fclose=func(__filehandle){};
|
nasal_call_inline_c_fclose(filehandle);
|
||||||
call_c_fclose(filehandle);
|
|
||||||
return;
|
return;
|
||||||
},
|
},
|
||||||
# Attempts to read length bytes from the filehandle into the beginning of the mutable string buf.
|
# Attempts to read length bytes from the filehandle into the beginning of the mutable string buf.
|
||||||
|
@ -26,16 +24,14 @@ var io=
|
||||||
# Returns the number of bytes successfully read.
|
# Returns the number of bytes successfully read.
|
||||||
read:func(filehandle,buf,length)
|
read:func(filehandle,buf,length)
|
||||||
{
|
{
|
||||||
var call_c_read=func(__filehandle,__buf,__len){};
|
return nasal_call_inline_c_read(filehandle,buf,length);
|
||||||
return call_c_read(filehandle,buf,length);
|
|
||||||
},
|
},
|
||||||
# Attempts to write the entirety of the specified string to the filehandle.
|
# Attempts to write the entirety of the specified string to the filehandle.
|
||||||
# Failures are thrown as runtime errors as per die().
|
# Failures are thrown as runtime errors as per die().
|
||||||
# Returns the number of bytes successfully written.
|
# Returns the number of bytes successfully written.
|
||||||
write:func(filehandle,str)
|
write:func(filehandle,str)
|
||||||
{
|
{
|
||||||
var call_c_write=func(__filehandle,__str){};
|
return nasal_call_inline_c_write(filehandle,str);
|
||||||
return call_c_write(filehandle,str);
|
|
||||||
},
|
},
|
||||||
# As ANSI fseek().
|
# As ANSI fseek().
|
||||||
# Attempts to seek to the specified position based on the whence value
|
# Attempts to seek to the specified position based on the whence value
|
||||||
|
@ -45,15 +41,13 @@ var io=
|
||||||
SEEK_END:3,
|
SEEK_END:3,
|
||||||
seek:func(filehandle,position,whence)
|
seek:func(filehandle,position,whence)
|
||||||
{
|
{
|
||||||
var call_c_seek=func(__filehandle,__position,__whence){};
|
nasal_call_inline_c_seek(filehandle,position,whence);
|
||||||
call_c_seek(filehandle,position,whence);
|
|
||||||
return;
|
return;
|
||||||
},
|
},
|
||||||
# Returns the current seek position of the filehandle.
|
# Returns the current seek position of the filehandle.
|
||||||
tell:func(filehandle)
|
tell:func(filehandle)
|
||||||
{
|
{
|
||||||
var call_c_tell=func(__filehandle){};
|
return nasal_call_inline_c_tell(filehandle);
|
||||||
return call_c_tell(filehandle);
|
|
||||||
},
|
},
|
||||||
# Reads and returns a single text line from the filehandle.
|
# Reads and returns a single text line from the filehandle.
|
||||||
# Interprets both "\n" and "\r\n" as end of line markers,
|
# Interprets both "\n" and "\r\n" as end of line markers,
|
||||||
|
@ -61,8 +55,7 @@ var io=
|
||||||
# End offile or error is signaled by returning nil.
|
# End offile or error is signaled by returning nil.
|
||||||
readln:func(filehandle)
|
readln:func(filehandle)
|
||||||
{
|
{
|
||||||
var call_builtin_c_getline=func(__filehandle){};
|
return nasal_call_inline_builtin_c_getline(filehandle);
|
||||||
return call_builtin_c_getline(filehandle);
|
|
||||||
},
|
},
|
||||||
# Calls unix or win32 stat() on the specified file name and
|
# Calls unix or win32 stat() on the specified file name and
|
||||||
# returns a seven element array whose contents are,
|
# returns a seven element array whose contents are,
|
||||||
|
@ -70,15 +63,13 @@ var io=
|
||||||
# Errors are signaled as exceptions as per die().
|
# Errors are signaled as exceptions as per die().
|
||||||
stat:func(filename)
|
stat:func(filename)
|
||||||
{
|
{
|
||||||
var call_builtin_stat=func(__filename){};
|
return nasal_call_inline_builtin_stat(filename);
|
||||||
return call_builtin_stat(filename);
|
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
var print=func(dyn...)
|
var print=func(dyn...)
|
||||||
{
|
{
|
||||||
var __system_call_c_std_puts=func(__str){};
|
|
||||||
forindex(var i;dyn)
|
forindex(var i;dyn)
|
||||||
__system_call_c_std_puts(dyn[i]);
|
nasal_call_inline_c_std_puts(dyn[i]);
|
||||||
return nil;
|
return nil;
|
||||||
};
|
};
|
|
@ -13,40 +13,37 @@ var math=
|
||||||
# Returns the sine of the single argument
|
# Returns the sine of the single argument
|
||||||
sin:func(x)
|
sin:func(x)
|
||||||
{
|
{
|
||||||
var call_inline_sin=func(__x){};
|
return nasal_call_inline_sin(x);
|
||||||
return call_inline_sin(x);
|
|
||||||
},
|
},
|
||||||
# Returns the cosine of the single argument
|
# Returns the cosine of the single argument
|
||||||
cos:func(x)
|
cos:func(x)
|
||||||
{
|
{
|
||||||
var call_inline_cos=func(__x){};
|
return nasal_call_inline_cos(x);
|
||||||
return call_inline_cos(x);
|
|
||||||
},
|
},
|
||||||
# you know what the f*ck this is
|
# you know what the f*ck this is
|
||||||
tan:func(x){return me.sin(x)/me.cos(x);},
|
tan:func(x)
|
||||||
|
{
|
||||||
|
return nasal_call_inline_tan(x);
|
||||||
|
},
|
||||||
# Returns e (Euler's constant) raised to the power specified by the single argument
|
# Returns e (Euler's constant) raised to the power specified by the single argument
|
||||||
exp:func(x)
|
exp:func(x)
|
||||||
{
|
{
|
||||||
var call_inline_pow=func(__num,__x){};
|
return nasal_call_inline_pow(me.e,x);
|
||||||
return call_inline_pow(me.e,x);
|
|
||||||
},
|
},
|
||||||
# Returns the natural logarithm of the single argument.
|
# Returns the natural logarithm of the single argument.
|
||||||
ln:func(x)
|
ln:func(x)
|
||||||
{
|
{
|
||||||
var call_inline_cpp_math_ln=func(__x){};
|
return nasal_call_inline_cpp_math_ln(x);
|
||||||
return call_inline_cpp_math_ln(x);
|
|
||||||
},
|
},
|
||||||
# Returns the square root of the single argument.
|
# Returns the square root of the single argument.
|
||||||
sqrt:func(x)
|
sqrt:func(x)
|
||||||
{
|
{
|
||||||
var call_inline_cpp_math_sqrt=func(__x){};
|
return nasal_call_inline_cpp_math_sqrt(x);
|
||||||
return call_inline_cpp_math_sqrt(x);
|
|
||||||
},
|
},
|
||||||
# Returns the arctangent of y/x, with the correct sign for the quadrant.
|
# Returns the arctangent of y/x, with the correct sign for the quadrant.
|
||||||
# Wraps the ANSI C function of the same name.
|
# Wraps the ANSI C function of the same name.
|
||||||
atan2:func(x,y)
|
atan2:func(x,y)
|
||||||
{
|
{
|
||||||
var call_inline_cpp_atan2=func(__num1,__num2){};
|
return nasal_call_inline_cpp_atan2(x,y);
|
||||||
return call_inline_cpp_atan2(x,y);
|
|
||||||
},
|
},
|
||||||
};
|
};
|
|
@ -192,6 +192,7 @@ class gc_manager
|
||||||
if(!memory[addr].refcnt)
|
if(!memory[addr].refcnt)
|
||||||
{
|
{
|
||||||
// if refcnt is 0,then starting the destructor
|
// if refcnt is 0,then starting the destructor
|
||||||
|
// std::cout<<">> [Gc] collected ";prt_hex(addr);std::cout<<std::endl;
|
||||||
memory[addr].collected=true;
|
memory[addr].collected=true;
|
||||||
switch(memory[addr].elem.get_type())
|
switch(memory[addr].elem.get_type())
|
||||||
{
|
{
|
||||||
|
@ -203,6 +204,7 @@ class gc_manager
|
||||||
default:break;
|
default:break;
|
||||||
}
|
}
|
||||||
memory[addr].elem.set_type(scalar_nil);
|
memory[addr].elem.set_type(scalar_nil);
|
||||||
|
free_space.push_back(addr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
|
@ -1,5 +1,41 @@
|
||||||
#ifndef __NASAL_RUNTIME_H__
|
#ifndef __NASAL_RUNTIME_H__
|
||||||
#define __NASAL_RUNTIME_H__
|
#define __NASAL_RUNTIME_H__
|
||||||
|
#define nas_lib_func_num 29
|
||||||
|
std::string inline_func_name[nas_lib_func_num]=
|
||||||
|
{
|
||||||
|
//base.nas
|
||||||
|
"nasal_call_inline_push_null",
|
||||||
|
"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",
|
||||||
|
//bits.nas
|
||||||
|
"nasal_call_built_in_bitcalc",
|
||||||
|
"nasal_call_built_in_sbitcalc",
|
||||||
|
"nasal_call_built_in_setbit",
|
||||||
|
"nasal_call_built_in_null_string_gen",
|
||||||
|
//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"
|
||||||
|
};
|
||||||
|
|
||||||
class nasal_runtime
|
class nasal_runtime
|
||||||
{
|
{
|
||||||
|
@ -42,7 +78,7 @@ class nasal_runtime
|
||||||
__special_call_vector_negative_value,
|
__special_call_vector_negative_value,
|
||||||
__special_call_vector_too_large_value,
|
__special_call_vector_too_large_value,
|
||||||
__normal_call_vector_too_large_value,
|
__normal_call_vector_too_large_value,
|
||||||
__error_call_type_when_getting_address,
|
__function_returned_value_be_assigned,
|
||||||
__call_function_lack_para,
|
__call_function_lack_para,
|
||||||
__forindex_foreach_not_vector,
|
__forindex_foreach_not_vector,
|
||||||
__break_not_used_in_loop,
|
__break_not_used_in_loop,
|
||||||
|
@ -67,6 +103,7 @@ class nasal_runtime
|
||||||
int conditional (std::list<std::map<std::string,int> >&,abstract_syntax_tree&);// checked
|
int conditional (std::list<std::map<std::string,int> >&,abstract_syntax_tree&);// checked
|
||||||
int block_proc (std::list<std::map<std::string,int> >&,abstract_syntax_tree&);// checked
|
int block_proc (std::list<std::map<std::string,int> >&,abstract_syntax_tree&);// checked
|
||||||
int func_proc (std::list<std::map<std::string,int> >&,abstract_syntax_tree&,abstract_syntax_tree&,abstract_syntax_tree&,int);// checked
|
int func_proc (std::list<std::map<std::string,int> >&,abstract_syntax_tree&,abstract_syntax_tree&,abstract_syntax_tree&,int);// checked
|
||||||
|
int inline_function (std::list<std::map<std::string,int> >&,abstract_syntax_tree&,int);
|
||||||
public:
|
public:
|
||||||
nasal_runtime()
|
nasal_runtime()
|
||||||
{
|
{
|
||||||
|
@ -124,8 +161,8 @@ void nasal_runtime::error_interrupt(const int type,const int line)
|
||||||
std::cout<<"the number used to call the sub-vector is too large(over 0x7fffffff)."<<std::endl;break;
|
std::cout<<"the number used to call the sub-vector is too large(over 0x7fffffff)."<<std::endl;break;
|
||||||
case __normal_call_vector_too_large_value:
|
case __normal_call_vector_too_large_value:
|
||||||
std::cout<<"the number used to call the vector is too large(over 0x7fffffff)."<<std::endl;break;
|
std::cout<<"the number used to call the vector is too large(over 0x7fffffff)."<<std::endl;break;
|
||||||
case __error_call_type_when_getting_address:
|
case __function_returned_value_be_assigned:
|
||||||
std::cout<<"this type of calling identifier is not allowed here."<<std::endl;break;
|
std::cout<<"cannot assigned a value that function returns."<<std::endl;break;
|
||||||
case __call_function_lack_para:
|
case __call_function_lack_para:
|
||||||
std::cout<<"lack parameter(s) when calling a function."<<std::endl;break;
|
std::cout<<"lack parameter(s) when calling a function."<<std::endl;break;
|
||||||
case __forindex_foreach_not_vector:
|
case __forindex_foreach_not_vector:
|
||||||
|
@ -1799,10 +1836,296 @@ int nasal_runtime::calculation(std::list<std::map<std::string,int> >& local_scop
|
||||||
}
|
}
|
||||||
int nasal_runtime::assignment(std::list<std::map<std::string,int> >& local_scope,abstract_syntax_tree& node,int data_addr)
|
int nasal_runtime::assignment(std::list<std::map<std::string,int> >& local_scope,abstract_syntax_tree& node,int data_addr)
|
||||||
{
|
{
|
||||||
int ret_addr=-1;
|
int* assigned_addr=NULL;
|
||||||
|
std::string tmp_id_name=node.get_var_name();
|
||||||
|
if(global_scope.find(tmp_id_name)!=global_scope.end())
|
||||||
return ret_addr;
|
assigned_addr=&(global_scope[tmp_id_name]);
|
||||||
|
for(std::list<std::map<std::string,int> >::iterator iter=local_scope.begin();iter!=local_scope.end();++iter)
|
||||||
|
if(iter->find(tmp_id_name)!=iter->end())
|
||||||
|
assigned_addr=&((*iter)[tmp_id_name]);
|
||||||
|
if(!assigned_addr)
|
||||||
|
return -1;
|
||||||
|
int assigned_value_addr=*assigned_addr;
|
||||||
|
for(std::list<abstract_syntax_tree>::iterator iter=node.get_children().begin();iter!=node.get_children().end();++iter)
|
||||||
|
{
|
||||||
|
// call vector/special call hash/subvec
|
||||||
|
// the special type of calling hash like a["name"] is also generated as calling vector
|
||||||
|
if(iter->get_node_type()==__call_vector)
|
||||||
|
{
|
||||||
|
// check the scalar type of called identifier here
|
||||||
|
int called_type=nasal_gc.get_scalar(assigned_value_addr).get_type();
|
||||||
|
if(called_type!=scalar_vector && called_type!=scalar_hash)
|
||||||
|
{
|
||||||
|
error_interrupt(__error_value_type,iter->get_node_line());
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
if(iter->get_children().front().get_node_type()==__sub_vector)
|
||||||
|
{
|
||||||
|
if(called_type==scalar_hash)
|
||||||
|
{
|
||||||
|
error_interrupt(__not_callable_vector,iter->get_node_line());
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
int num1_addr=-1;
|
||||||
|
int num2_addr=-1;
|
||||||
|
// identifier[num1:];
|
||||||
|
if(iter->get_children().front().get_children().size()==1)
|
||||||
|
{
|
||||||
|
num1_addr=calculation(local_scope,iter->get_children().front().get_children().front());
|
||||||
|
if(num1_addr<0)
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
// identifier[num1:num2];
|
||||||
|
else
|
||||||
|
{
|
||||||
|
num1_addr=calculation(local_scope,iter->get_children().front().get_children().front());
|
||||||
|
num2_addr=calculation(local_scope,iter->get_children().front().get_children().back());
|
||||||
|
if(num1_addr<0 || num2_addr<0)
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
if(nasal_gc.get_scalar(num1_addr).get_type()!=scalar_number
|
||||||
|
&& nasal_gc.get_scalar(num1_addr).get_type()!=scalar_string)
|
||||||
|
{
|
||||||
|
error_interrupt(__error_value_type_when_calling_vector,iter->get_children().front().get_children().front().get_node_line());
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
if(num2_addr>=0
|
||||||
|
&& (nasal_gc.get_scalar(num2_addr).get_type()!=scalar_number
|
||||||
|
&& nasal_gc.get_scalar(num2_addr).get_type()!=scalar_string
|
||||||
|
&& nasal_gc.get_scalar(num2_addr).get_type()!=scalar_nil))
|
||||||
|
{
|
||||||
|
error_interrupt(__error_value_type_when_calling_vector,iter->get_children().front().get_children().back().get_node_line());
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
if(nasal_gc.get_scalar(num1_addr).get_type()==scalar_string)
|
||||||
|
{
|
||||||
|
if(check_numerable_string(nasal_gc.get_scalar(num1_addr).get_string().get_string()))
|
||||||
|
{
|
||||||
|
double tmp_num=trans_string_to_number(nasal_gc.get_scalar(num1_addr).get_string().get_string());
|
||||||
|
if(tmp_num<0)
|
||||||
|
{
|
||||||
|
error_interrupt(__special_call_vector_negative_value,iter->get_children().front().get_children().front().get_node_line());
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
nasal_gc.reference_delete(num1_addr);
|
||||||
|
num1_addr=nasal_gc.gc_alloc();
|
||||||
|
nasal_gc.get_scalar(num1_addr).set_type(scalar_number);
|
||||||
|
nasal_gc.get_scalar(num1_addr).get_number().set_number(tmp_num);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
error_interrupt(__not_numerable_str,iter->get_children().front().get_children().front().get_node_line());
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(num2_addr>=0 && nasal_gc.get_scalar(num2_addr).get_type()==scalar_string)
|
||||||
|
{
|
||||||
|
if(check_numerable_string(nasal_gc.get_scalar(num2_addr).get_string().get_string()))
|
||||||
|
{
|
||||||
|
double tmp_num=trans_string_to_number(nasal_gc.get_scalar(num2_addr).get_string().get_string());
|
||||||
|
if(tmp_num<0)
|
||||||
|
{
|
||||||
|
error_interrupt(__special_call_vector_negative_value,iter->get_children().front().get_children().back().get_node_line());
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
nasal_gc.reference_delete(num2_addr);
|
||||||
|
num2_addr=nasal_gc.gc_alloc();
|
||||||
|
nasal_gc.get_scalar(num2_addr).set_type(scalar_number);
|
||||||
|
nasal_gc.get_scalar(num2_addr).get_number().set_number(tmp_num);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
error_interrupt(__not_numerable_str,iter->get_children().front().get_children().back().get_node_line());
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(nasal_gc.get_scalar(num1_addr).get_number().get_number()>2147483647)
|
||||||
|
{
|
||||||
|
error_interrupt(__special_call_vector_too_large_value,iter->get_children().front().get_children().front().get_node_line());
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
if(num2_addr>=0 && nasal_gc.get_scalar(num2_addr).get_number().get_number()>2147483647)
|
||||||
|
{
|
||||||
|
error_interrupt(__special_call_vector_too_large_value,iter->get_children().front().get_children().back().get_node_line());
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
int begin_num=(int)nasal_gc.get_scalar(num1_addr).get_number().get_number();
|
||||||
|
int end_num=0;
|
||||||
|
if(num2_addr<0 || nasal_gc.get_scalar(num2_addr).get_type()==scalar_nil)
|
||||||
|
end_num=nasal_gc.get_scalar(assigned_value_addr).get_vector().get_size();
|
||||||
|
else
|
||||||
|
end_num=(int)nasal_gc.get_scalar(num2_addr).get_number().get_number();
|
||||||
|
if(num1_addr>=0)
|
||||||
|
nasal_gc.reference_delete(num1_addr);
|
||||||
|
if(num2_addr>=0)
|
||||||
|
nasal_gc.reference_delete(num2_addr);
|
||||||
|
std::vector<int> subvec_result;
|
||||||
|
for(int i=begin_num;i<end_num;++i)
|
||||||
|
{
|
||||||
|
// addr used here
|
||||||
|
int tmp_data_addr=nasal_gc.get_scalar(assigned_value_addr).get_vector().get_elem(i);
|
||||||
|
int new_addr=-1;
|
||||||
|
if(tmp_data_addr<0)
|
||||||
|
{
|
||||||
|
error_interrupt(__invalid_vector_member,iter->get_children().front().get_children().front().get_node_line());
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
switch(nasal_gc.get_scalar(tmp_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(tmp_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(tmp_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(tmp_data_addr).get_function());
|
||||||
|
break;
|
||||||
|
case scalar_vector:
|
||||||
|
case scalar_hash:
|
||||||
|
new_addr=tmp_data_addr;
|
||||||
|
nasal_gc.reference_add(new_addr);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
nasal_gc.reference_delete(tmp_data_addr);
|
||||||
|
subvec_result.push_back(new_addr);
|
||||||
|
}
|
||||||
|
int tmp_addr=assigned_value_addr;
|
||||||
|
assigned_value_addr=nasal_gc.gc_alloc();
|
||||||
|
nasal_gc.get_scalar(assigned_value_addr).set_type(scalar_vector);
|
||||||
|
for(int i=0;i<subvec_result.size();++i)
|
||||||
|
nasal_gc.get_scalar(assigned_value_addr).get_vector().vec_push(subvec_result[i]);
|
||||||
|
nasal_gc.reference_delete(tmp_addr);
|
||||||
|
assigned_addr=NULL;
|
||||||
|
}// end sub-vector
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// normal vector/hash calling
|
||||||
|
int data_addr=calculation(local_scope,iter->get_children().front());
|
||||||
|
if(data_addr<0)
|
||||||
|
return -1;
|
||||||
|
if(nasal_gc.get_scalar(data_addr).get_type()!=scalar_number && nasal_gc.get_scalar(data_addr).get_type()!=scalar_string)
|
||||||
|
{
|
||||||
|
error_interrupt(__error_value_type_when_calling_vector,iter->get_children().front().get_node_line());
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
if(called_type==scalar_vector)
|
||||||
|
{
|
||||||
|
double place_num=0;
|
||||||
|
if(nasal_gc.get_scalar(data_addr).get_type()==scalar_string)
|
||||||
|
{
|
||||||
|
if(check_numerable_string(nasal_gc.get_scalar(data_addr).get_string().get_string()))
|
||||||
|
place_num=(int)trans_string_to_number(nasal_gc.get_scalar(data_addr).get_string().get_string());
|
||||||
|
else
|
||||||
|
{
|
||||||
|
error_interrupt(__not_numerable_str,iter->get_children().front().get_node_line());
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(place_num>2147483647 || place_num<-2147483648)
|
||||||
|
{
|
||||||
|
error_interrupt(__normal_call_vector_too_large_value,iter->get_children().front().get_node_line());
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
int tmp_addr=assigned_value_addr;
|
||||||
|
assigned_addr=nasal_gc.get_scalar(tmp_addr).get_vector().get_elem_addr((int)place_num);
|
||||||
|
if(!assigned_addr)
|
||||||
|
{
|
||||||
|
error_interrupt(__invalid_vector_member,iter->get_children().front().get_children().front().get_node_line());
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
assigned_value_addr=*assigned_addr;
|
||||||
|
nasal_gc.reference_add(assigned_value_addr);
|
||||||
|
nasal_gc.reference_delete(tmp_addr);
|
||||||
|
}
|
||||||
|
else if(called_type==scalar_hash)
|
||||||
|
{
|
||||||
|
if(nasal_gc.get_scalar(data_addr).get_type()!=scalar_string)
|
||||||
|
{
|
||||||
|
error_interrupt(__error_value_type_when_calling_hash,iter->get_children().front().get_node_line());
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
int tmp_addr=assigned_value_addr;
|
||||||
|
assigned_addr=nasal_gc.get_scalar(tmp_addr).get_hash().get_hash_member_addr(nasal_gc.get_scalar(data_addr).get_string().get_string());
|
||||||
|
if(!assigned_addr)
|
||||||
|
{
|
||||||
|
error_interrupt(__invalid_hash_member,iter->get_children().front().get_node_line());
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
assigned_value_addr=*assigned_addr;
|
||||||
|
nasal_gc.reference_add(assigned_value_addr);
|
||||||
|
nasal_gc.reference_delete(tmp_addr);
|
||||||
|
}
|
||||||
|
nasal_gc.reference_delete(data_addr);
|
||||||
|
}
|
||||||
|
}// end call vector
|
||||||
|
// call hash identifier.identifier
|
||||||
|
else if(iter->get_node_type()==__call_hash)
|
||||||
|
{
|
||||||
|
if(nasal_gc.get_scalar(assigned_value_addr).get_type()!=scalar_hash)
|
||||||
|
{
|
||||||
|
error_interrupt(__not_callable_hash,iter->get_node_line());
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
int tmp_addr=assigned_value_addr;
|
||||||
|
assigned_addr=nasal_gc.get_scalar(assigned_value_addr).get_hash().get_hash_member_addr(iter->get_var_name());
|
||||||
|
if(!assigned_addr)
|
||||||
|
{
|
||||||
|
error_interrupt(__invalid_hash_member,iter->get_node_line());
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
assigned_value_addr=*assigned_addr;
|
||||||
|
nasal_gc.reference_add(assigned_value_addr);
|
||||||
|
nasal_gc.reference_delete(tmp_addr);
|
||||||
|
}// end call hash
|
||||||
|
// call function identifier(...)
|
||||||
|
else if(iter->get_node_type()==__call_function)
|
||||||
|
{
|
||||||
|
error_interrupt(__function_returned_value_be_assigned,iter->get_node_line());
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
switch(nasal_gc.get_scalar(data_addr).get_type())
|
||||||
|
{
|
||||||
|
case scalar_nil:
|
||||||
|
*assigned_addr=nasal_gc.gc_alloc();
|
||||||
|
nasal_gc.get_scalar(*assigned_addr).set_type(scalar_nil);
|
||||||
|
break;
|
||||||
|
case scalar_number:
|
||||||
|
*assigned_addr=nasal_gc.gc_alloc();
|
||||||
|
nasal_gc.get_scalar(*assigned_addr).set_type(scalar_number);
|
||||||
|
nasal_gc.get_scalar(*assigned_addr).get_number().deep_copy(nasal_gc.get_scalar(data_addr).get_number());
|
||||||
|
break;
|
||||||
|
case scalar_string:
|
||||||
|
*assigned_addr=nasal_gc.gc_alloc();
|
||||||
|
nasal_gc.get_scalar(*assigned_addr).set_type(scalar_string);
|
||||||
|
nasal_gc.get_scalar(*assigned_addr).get_string().deep_copy(nasal_gc.get_scalar(data_addr).get_string());
|
||||||
|
break;
|
||||||
|
case scalar_function:
|
||||||
|
*assigned_addr=nasal_gc.gc_alloc();
|
||||||
|
nasal_gc.get_scalar(*assigned_addr).set_type(scalar_function);
|
||||||
|
nasal_gc.get_scalar(*assigned_addr).get_function().deep_copy(nasal_gc.get_scalar(data_addr).get_function());
|
||||||
|
break;
|
||||||
|
case scalar_vector:
|
||||||
|
case scalar_hash:
|
||||||
|
*assigned_addr=data_addr;
|
||||||
|
nasal_gc.reference_add(data_addr);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
nasal_gc.reference_delete(assigned_value_addr);
|
||||||
|
// data_addr is only a parameter here,and it's refcnt has not been changed when using it here
|
||||||
|
nasal_gc.reference_add(*assigned_addr);
|
||||||
|
return *assigned_addr;
|
||||||
}
|
}
|
||||||
int nasal_runtime::call_identifier(std::list<std::map<std::string,int> >& local_scope,abstract_syntax_tree& node)
|
int nasal_runtime::call_identifier(std::list<std::map<std::string,int> >& local_scope,abstract_syntax_tree& node)
|
||||||
{
|
{
|
||||||
|
@ -1814,12 +2137,16 @@ int nasal_runtime::call_identifier(std::list<std::map<std::string,int> >& local_
|
||||||
if(iter->find(tmp_id_name)!=iter->end())
|
if(iter->find(tmp_id_name)!=iter->end())
|
||||||
addr=(*iter)[tmp_id_name];
|
addr=(*iter)[tmp_id_name];
|
||||||
if(addr<0)
|
if(addr<0)
|
||||||
|
{
|
||||||
|
for(int i=0;i<nas_lib_func_num;++i)
|
||||||
|
if(inline_func_name[i]==tmp_id_name)
|
||||||
|
addr=inline_function(local_scope,node,-1);
|
||||||
|
}
|
||||||
|
if(addr<0)
|
||||||
{
|
{
|
||||||
error_interrupt(__undefined_identifier,node.get_node_line());
|
error_interrupt(__undefined_identifier,node.get_node_line());
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
//addr refcnt+1
|
|
||||||
nasal_gc.reference_add(addr);
|
|
||||||
int last_hash_addr=-1;
|
int last_hash_addr=-1;
|
||||||
for(std::list<abstract_syntax_tree>::iterator iter=node.get_children().begin();iter!=node.get_children().end();++iter)
|
for(std::list<abstract_syntax_tree>::iterator iter=node.get_children().begin();iter!=node.get_children().end();++iter)
|
||||||
{
|
{
|
||||||
|
@ -2288,7 +2615,9 @@ int nasal_runtime::loop_expr(std::list<std::map<std::string,int> >& local_scope,
|
||||||
for(int i=0;i<nasal_gc.get_scalar(vec_addr).get_vector().get_size();++i)
|
for(int i=0;i<nasal_gc.get_scalar(vec_addr).get_vector().get_size();++i)
|
||||||
{
|
{
|
||||||
int now_step_elem_addr=nasal_gc.get_scalar(vec_addr).get_vector().get_elem(i);
|
int now_step_elem_addr=nasal_gc.get_scalar(vec_addr).get_vector().get_elem(i);
|
||||||
assignment(local_scope,assignment_ast,now_step_elem_addr);
|
int tmp_val=assignment(local_scope,assignment_ast,now_step_elem_addr);
|
||||||
|
if(tmp_val>=0)
|
||||||
|
nasal_gc.reference_delete(tmp_val);
|
||||||
int state=block_proc(local_scope,*iter);
|
int state=block_proc(local_scope,*iter);
|
||||||
if(state==__state_break)
|
if(state==__state_break)
|
||||||
break;
|
break;
|
||||||
|
@ -2301,6 +2630,7 @@ int nasal_runtime::loop_expr(std::list<std::map<std::string,int> >& local_scope,
|
||||||
else if(state==__state_no_operation)
|
else if(state==__state_no_operation)
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
|
nasal_gc.reference_delete(vec_addr);
|
||||||
}
|
}
|
||||||
else if(loop_type==__forindex)
|
else if(loop_type==__forindex)
|
||||||
{
|
{
|
||||||
|
@ -2335,7 +2665,9 @@ int nasal_runtime::loop_expr(std::list<std::map<std::string,int> >& local_scope,
|
||||||
int tmp_addr=nasal_gc.gc_alloc();
|
int tmp_addr=nasal_gc.gc_alloc();
|
||||||
nasal_gc.get_scalar(tmp_addr).set_type(scalar_number);
|
nasal_gc.get_scalar(tmp_addr).set_type(scalar_number);
|
||||||
nasal_gc.get_scalar(tmp_addr).get_number().set_number((double)i);
|
nasal_gc.get_scalar(tmp_addr).get_number().set_number((double)i);
|
||||||
assignment(local_scope,assignment_ast,tmp_addr);
|
int tmp_val=assignment(local_scope,assignment_ast,tmp_addr);
|
||||||
|
if(tmp_val>=0)
|
||||||
|
nasal_gc.reference_delete(tmp_val);
|
||||||
nasal_gc.reference_delete(tmp_addr);
|
nasal_gc.reference_delete(tmp_addr);
|
||||||
int state=block_proc(local_scope,*iter);
|
int state=block_proc(local_scope,*iter);
|
||||||
if(state==__state_break)
|
if(state==__state_break)
|
||||||
|
@ -2349,6 +2681,7 @@ int nasal_runtime::loop_expr(std::list<std::map<std::string,int> >& local_scope,
|
||||||
else if(state==__state_no_operation)
|
else if(state==__state_no_operation)
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
|
nasal_gc.reference_delete(vec_addr);
|
||||||
}
|
}
|
||||||
else if(loop_type==__for)
|
else if(loop_type==__for)
|
||||||
{
|
{
|
||||||
|
@ -2365,6 +2698,7 @@ int nasal_runtime::loop_expr(std::list<std::map<std::string,int> >& local_scope,
|
||||||
while(check_condition(local_scope,*condition_iterator))
|
while(check_condition(local_scope,*condition_iterator))
|
||||||
{
|
{
|
||||||
int state=block_proc(local_scope,*block_proc_iterator);
|
int state=block_proc(local_scope,*block_proc_iterator);
|
||||||
|
|
||||||
if(state==__state_break)
|
if(state==__state_break)
|
||||||
break;
|
break;
|
||||||
else if(state==__state_continue)
|
else if(state==__state_continue)
|
||||||
|
@ -2692,13 +3026,12 @@ void nasal_runtime::main_proc(abstract_syntax_tree& root)
|
||||||
{
|
{
|
||||||
time_t begin_time,end_time;
|
time_t begin_time,end_time;
|
||||||
begin_time=std::time(NULL);
|
begin_time=std::time(NULL);
|
||||||
|
|
||||||
// initializing global scope and nasal_gc
|
// initializing global scope and nasal_gc
|
||||||
// runtime_error_exit_mark is set to -1,if runtime_error_exit_mark >=0,this means an error occurred
|
// runtime_error_exit_mark is set to -1,if runtime_error_exit_mark >=0,this means an error occurred
|
||||||
global_scope.clear();
|
global_scope.clear();
|
||||||
|
main_local_scope.clear();
|
||||||
nasal_gc.gc_init();
|
nasal_gc.gc_init();
|
||||||
runtime_error_exit_mark=-1;
|
runtime_error_exit_mark=-1;
|
||||||
|
|
||||||
if(root.get_node_type()!=__root)
|
if(root.get_node_type()!=__root)
|
||||||
{
|
{
|
||||||
error_interrupt(__incorrect_head_of_tree,root.get_node_line());
|
error_interrupt(__incorrect_head_of_tree,root.get_node_line());
|
||||||
|
@ -2772,9 +3105,11 @@ void nasal_runtime::main_proc(abstract_syntax_tree& root)
|
||||||
else if(state==__state_error)
|
else if(state==__state_error)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
end_time=std::time(NULL);
|
end_time=std::time(NULL);
|
||||||
std::cout<<">> [Runtime] process exited after "<<end_time-begin_time<<" s ."<<std::endl;
|
std::cout<<">> [Runtime] process exited after "<<end_time-begin_time<<" s ."<<std::endl;
|
||||||
|
global_scope.clear();
|
||||||
|
main_local_scope.clear();
|
||||||
|
nasal_gc.gc_init();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue