diff --git a/README.md b/README.md index b78d602..38ac06d 100644 --- a/README.md +++ b/README.md @@ -141,7 +141,8 @@ Use these commands to get version of interpreter: / \/ / _` / __|/ _` | | / /\ / (_| \__ \ (_| | | \_\ \/ \__,_|___/\__,_|_| -nasal interpreter ver 9.0 +nasal ver : 9.0 +c++ std : 201103 thanks to : https://github.com/andyross/nasal code repo : https://github.com/ValKmjolnir/Nasal-Interpreter code repo : https://gitee.com/valkmjolnir/Nasal-Interpreter diff --git a/lib.nas b/lib.nas index aae4964..e3d2476 100644 --- a/lib.nas +++ b/lib.nas @@ -363,6 +363,8 @@ var math= pi: 3.14159265358979323846264338327950288, inf: 1/0, nan: 0/0, + abs: func(x) {return x>0?x:-x; }, + floor: func(x) {return __builtin_floor(x); }, pow: func(x,y){return __builtin_pow(x,y); }, sin: func(x) {return __builtin_sin(x); }, cos: func(x) {return __builtin_cos(x); }, diff --git a/main.cpp b/main.cpp index 1b68716..03a705d 100644 --- a/main.cpp +++ b/main.cpp @@ -1,14 +1,14 @@ #include "nasal.h" -const uint32_t VM_LEXINFO =1; -const uint32_t VM_ASTINFO =2; -const uint32_t VM_CODEINFO =4; -const uint32_t VM_EXECTIME =8; -const uint32_t VM_OPCALLNUM=16; -const uint32_t VM_EXEC =32; -const uint32_t VM_DBGINFO =64; -const uint32_t VM_DEBUG =128; -const uint32_t VM_OPTIMIZE =256; +const uint32_t VM_LEXINFO =0x01; +const uint32_t VM_ASTINFO =0x02; +const uint32_t VM_CODEINFO =0x04; +const uint32_t VM_EXECTIME =0x08; +const uint32_t VM_OPCALLNUM=0x10; +const uint32_t VM_EXEC =0x20; +const uint32_t VM_DBGINFO =0x40; +const uint32_t VM_DEBUG =0x80; +const uint32_t VM_OPTIMIZE =0x100; void help() { @@ -43,10 +43,10 @@ void help() void logo() { std::cout - <<" __ _ \n" - <<" /\\ \\ \\__ _ ___ __ _| | \n" - <<" / \\/ / _` / __|/ _` | | \n" - <<" / /\\ / (_| \\__ \\ (_| | | \n" + <<" __ _\n" + <<" /\\ \\ \\__ _ ___ __ _| |\n" + <<" / \\/ / _` / __|/ _` | |\n" + <<" / /\\ / (_| \\__ \\ (_| | |\n" <<" \\_\\ \\/ \\__,_|___/\\__,_|_|\n" <<"nasal ver : "<<__nasver<<"\n" <<"c++ std : "<<__cplusplus<<"\n" diff --git a/nasal_builtin.h b/nasal_builtin.h index 22d5626..8440625 100644 --- a/nasal_builtin.h +++ b/nasal_builtin.h @@ -671,12 +671,14 @@ nasal_ref builtin_substr(nasal_ref* local,nasal_gc& gc) return builtin_err("substr","\"begin\" must be number"); if(len.type!=vm_num) return builtin_err("substr","\"length\" must be number"); - int begin=(int)beg.num(); - int length=(int)len.num(); - if(begin>=str.str().length() || begin+length-1>=str.str().length()) + if(beg.num()<0) + return builtin_err("substr","\"begin\" should be greater than or equal to zero"); + if(len.num()<0) + return builtin_err("substr","\"length\" should be greater than or equal to zero"); + size_t begin=(size_t)beg.num(); + size_t length=(size_t)len.num(); + if(begin>=str.str().length() || begin+length>str.str().length()) return builtin_err("susbtr","index out of range"); - if(length<0) - length=0; nasal_ref ret=gc.alloc(vm_str); ret.str()=str.str().substr(begin,length); return ret; diff --git a/nasal_vm.h b/nasal_vm.h index 172e4d0..2cb5e2c 100644 --- a/nasal_vm.h +++ b/nasal_vm.h @@ -629,7 +629,7 @@ inline void nasal_vm::opr_counter() } inline void nasal_vm::opr_findex() { - if(++gc.top[0].cnt()>=gc.top[-1].vec().size()) + if((size_t)(++gc.top[0].cnt())>=gc.top[-1].vec().size()) { pc=imm[pc]-1; return; @@ -640,7 +640,7 @@ inline void nasal_vm::opr_findex() inline void nasal_vm::opr_feach() { std::vector& ref=gc.top[-1].vec().elems; - if(++gc.top[0].cnt()>=ref.size()) + if((size_t)(++gc.top[0].cnt())>=ref.size()) { pc=imm[pc]-1; return; diff --git a/stl/lib.nas b/stl/lib.nas index aae4964..e3d2476 100644 --- a/stl/lib.nas +++ b/stl/lib.nas @@ -363,6 +363,8 @@ var math= pi: 3.14159265358979323846264338327950288, inf: 1/0, nan: 0/0, + abs: func(x) {return x>0?x:-x; }, + floor: func(x) {return __builtin_floor(x); }, pow: func(x,y){return __builtin_pow(x,y); }, sin: func(x) {return __builtin_sin(x); }, cos: func(x) {return __builtin_cos(x); }, diff --git a/test/scalar.nas b/test/scalar.nas index 49f46a8..3da440a 100644 --- a/test/scalar.nas +++ b/test/scalar.nas @@ -197,4 +197,7 @@ var a=[10,-10,0,1,2,3,nil,"string","hello",[],[0,1,2,3],{},{a:0,b:1,c:2},func{}] println("type\tsize\tnum\tsrc"); foreach(var i;a){ println(typeof(i),'\t',size(i),'\t',num(i),'\t',i); +} +foreach(i;a){ + ; } \ No newline at end of file