diff --git a/lib.nas b/lib.nas index 9669f67..08a1c4d 100644 --- a/lib.nas +++ b/lib.nas @@ -49,7 +49,7 @@ var id=func(object){ return __id(object); } -# int will get the integer of input number. +# int will get the integer of input number/string. # but carefully use it, because int has range between -2147483648~2147483647 var int=func(val){ return __int(val); diff --git a/nasal_builtin.h b/nasal_builtin.h index ba00ea9..ad24280 100644 --- a/nasal_builtin.h +++ b/nasal_builtin.h @@ -193,9 +193,9 @@ nas_ref builtin_id(nas_ref* local,nasal_gc& gc) nas_ref builtin_int(nas_ref* local,nasal_gc& gc) { nas_ref val=local[1]; - if(val.type!=vm_num) + if(val.type!=vm_num && val.type!=vm_str) return nil; - return {vm_num,f64((i32)val.num())}; + return {vm_num,f64((i32)val.tonum())}; } nas_ref builtin_floor(nas_ref* local,nasal_gc& gc) { diff --git a/stl/lib.nas b/stl/lib.nas index 9669f67..08a1c4d 100644 --- a/stl/lib.nas +++ b/stl/lib.nas @@ -49,7 +49,7 @@ var id=func(object){ return __id(object); } -# int will get the integer of input number. +# int will get the integer of input number/string. # but carefully use it, because int has range between -2147483648~2147483647 var int=func(val){ return __int(val); diff --git a/test/calc.nas b/test/calc.nas index 05dfccd..061c488 100644 --- a/test/calc.nas +++ b/test/calc.nas @@ -57,6 +57,7 @@ var testfile=[ "loop.nas", "mandel.nas", "mandelbrot.nas", + "mcpu.nas", "md5.nas", "md5compare.nas", "module_test.nas", @@ -97,12 +98,6 @@ var longest=func(vec...){ } var padding_length=longest(source,lib,testfile,module); -var getname=func(s){ - var (len,ch)=(size(s),' '[0]); - for(var i=0;ireg[ir[3]]; + }elsif(op==inst.inst_leq){ + reg[ir[1]]=reg[ir[2]]<=reg[ir[3]]; + }elsif(op==inst.inst_geq){ + reg[ir[1]]=reg[ir[2]]>=reg[ir[3]]; + }elsif(op==inst.inst_eq){ + reg[ir[1]]=reg[ir[2]]==reg[ir[3]]; + }elsif(op==inst.inst_in){ + reg[0]=0; # unfinished + }elsif(op==inst.inst_out){ + println("reg[",ir[1],"]: 0x",hex32(reg[ir[1]])); + } + pc+=4; + } +}; + return {exec:exec}; +}( +hex(inst.inst_mov_reg_imm_high)~" 01 ca fe "~ # reg[1]=0xcafe0000 +hex(inst.inst_mov_reg_imm_low)~" 01 ba be "~ # reg[1]=0xcafebabe +hex(inst.inst_out)~" 01 00 00 "~ # output reg[1] +hex(inst.inst_mov_reg_imm_low)~" 02 00 20 "~ # reg[2]=0x10 +hex(inst.inst_jmp)~" 02 00 00 "~ # jmp *reg[2] +hex(inst.inst_out)~" 01 00 00 "~ +hex(inst.inst_out)~" 01 00 00 "~ +hex(inst.inst_out)~" 01 00 00 "~ +hex(inst.inst_out)~" 01 00 00 "~ +hex(inst.inst_out)~" 01 00 00 "~ # should jump here +hex(inst.inst_jf)~" 01 02 00 "~ # should not jump +hex(inst.inst_mov_reg_imm_low)~" 03 00 04 "~ # reg[3]=4 +hex(inst.inst_mov_reg_imm_low)~" 04 00 00 "~ # reg[4]=0 +hex(inst.inst_out)~" 04 00 00 "~ # output reg[4] +hex(inst.inst_grt)~" 00 04 03 "~ # reg[0]=reg[4]>reg[3] +hex(inst.inst_mov_reg_imm_low)~" 05 00 30 "~ # reg[5]=0x2c +hex(inst.inst_mov_reg_imm_low)~" 06 00 01 "~ # reg[6]=1 +hex(inst.inst_add)~" 04 04 06 "~ # reg[4]+=reg[6] +hex(inst.inst_jf)~" 00 05 00 " # jmp *reg[5] if reg[0]!=true +); + +machine.exec(0); \ No newline at end of file diff --git a/test/md5compare.nas b/test/md5compare.nas index 06d8fb8..33eaf37 100644 --- a/test/md5compare.nas +++ b/test/md5compare.nas @@ -51,6 +51,7 @@ var filechecksum=func(){ "./test/leetcode1319.nas", "./test/lexer.nas", "./test/life.nas", "./test/loop.nas", "./test/mandel.nas", "./test/mandelbrot.nas", + "./test/mcpu.nas", "./test/md5.nas", "./test/md5compare.nas", "./test/module_test.nas", "./test/nasal_test.nas", "./test/occupation.nas", "./test/pi.nas",