bug fixed & add systime, finished vecindex

This commit is contained in:
ValKmjolnir 2022-04-04 19:08:48 +08:00
parent aed5e27409
commit 399b2f0ce9
4 changed files with 30 additions and 7 deletions

View File

@ -211,7 +211,7 @@ var isnum=func(x){
var isscalar=func(s){
var t=typeof(s);
return t=="num" or t=="str";
return (t=="num" or t=="str")?1:0;
}
var isstr=func(s){
@ -223,7 +223,9 @@ var isvec=func(v){
}
var vecindex=func(vec,val){
# unfinished
forindex(var i;vec)
if(val==vec[i])
return i;
return nil;
}

View File

@ -521,7 +521,8 @@ inline void nasal_vm::opr_eq()
gc.top[0]=one;
else if(val1.type==vm_str && val2.type==vm_str)
gc.top[0]=(val1.str()==val2.str())?one:zero;
else if(val1.type==vm_num || val2.type==vm_num)
else if((val1.type==vm_num || val2.type==vm_num)
&& val1.type!=vm_nil && val2.type!=vm_nil)
gc.top[0]=(val1.to_number()==val2.to_number())?one:zero;
else
gc.top[0]=(val1==val2)?one:zero;
@ -534,7 +535,8 @@ inline void nasal_vm::opr_neq()
gc.top[0]=zero;
else if(val1.type==vm_str && val2.type==vm_str)
gc.top[0]=(val1.str()!=val2.str())?one:zero;
else if(val1.type==vm_num || val2.type==vm_num)
else if((val1.type==vm_num || val2.type==vm_num)
&& val1.type!=vm_nil && val2.type!=vm_nil)
gc.top[0]=(val1.to_number()!=val2.to_number())?one:zero;
else
gc.top[0]=(val1!=val2)?one:zero;

View File

@ -211,7 +211,7 @@ var isnum=func(x){
var isscalar=func(s){
var t=typeof(s);
return t=="num" or t=="str";
return (t=="num" or t=="str")?1:0;
}
var isstr=func(s){
@ -223,7 +223,9 @@ var isvec=func(v){
}
var vecindex=func(vec,val){
# unfinished
forindex(var i;vec)
if(val==vec[i])
return i;
return nil;
}

View File

@ -149,4 +149,21 @@ f1() or f2();
# print '1'
# this means that when using 'or' or 'and',
# if the result is clear when calculating,
# objects behind will not be calculated
# objects behind will not be calculated
print(
subvec([0,1,2,3],2),'\n',
subvec([0,1,2,3],2,1),'\n',
abs(1),'\n',
abs(-1),'\n',
systime(),'\n',
isfunc(func{}),' ',isfunc([]),'\n',
ishash({}),' ',ishash([]),'\n',
isint(114.514),' ',isint(114514),'\n',
isnum("0xaa55"),' ',isnum("?"),'\n',
isscalar(0.618),' ',isscalar("hello"),' ',isscalar([]),'\n',
isstr("hello"),' ',isstr(func{}),'\n',
isvec([]),' ',isvec("[]"),'\n',
vecindex([0,1,2,3,4],1),'\n',
vecindex(["apple","banana"],"apple")!=nil,'\n'
);