🐛 bug fix
This commit is contained in:
parent
fd8a148d0c
commit
23a5c1b1ad
|
@ -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
|
thanks to : https://github.com/andyross/nasal
|
||||||
code repo : https://github.com/ValKmjolnir/Nasal-Interpreter
|
code repo : https://github.com/ValKmjolnir/Nasal-Interpreter
|
||||||
code repo : https://gitee.com/valkmjolnir/Nasal-Interpreter
|
code repo : https://gitee.com/valkmjolnir/Nasal-Interpreter
|
||||||
|
|
2
lib.nas
2
lib.nas
|
@ -363,6 +363,8 @@ var math=
|
||||||
pi: 3.14159265358979323846264338327950288,
|
pi: 3.14159265358979323846264338327950288,
|
||||||
inf: 1/0,
|
inf: 1/0,
|
||||||
nan: 0/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); },
|
pow: func(x,y){return __builtin_pow(x,y); },
|
||||||
sin: func(x) {return __builtin_sin(x); },
|
sin: func(x) {return __builtin_sin(x); },
|
||||||
cos: func(x) {return __builtin_cos(x); },
|
cos: func(x) {return __builtin_cos(x); },
|
||||||
|
|
18
main.cpp
18
main.cpp
|
@ -1,14 +1,14 @@
|
||||||
#include "nasal.h"
|
#include "nasal.h"
|
||||||
|
|
||||||
const uint32_t VM_LEXINFO =1;
|
const uint32_t VM_LEXINFO =0x01;
|
||||||
const uint32_t VM_ASTINFO =2;
|
const uint32_t VM_ASTINFO =0x02;
|
||||||
const uint32_t VM_CODEINFO =4;
|
const uint32_t VM_CODEINFO =0x04;
|
||||||
const uint32_t VM_EXECTIME =8;
|
const uint32_t VM_EXECTIME =0x08;
|
||||||
const uint32_t VM_OPCALLNUM=16;
|
const uint32_t VM_OPCALLNUM=0x10;
|
||||||
const uint32_t VM_EXEC =32;
|
const uint32_t VM_EXEC =0x20;
|
||||||
const uint32_t VM_DBGINFO =64;
|
const uint32_t VM_DBGINFO =0x40;
|
||||||
const uint32_t VM_DEBUG =128;
|
const uint32_t VM_DEBUG =0x80;
|
||||||
const uint32_t VM_OPTIMIZE =256;
|
const uint32_t VM_OPTIMIZE =0x100;
|
||||||
|
|
||||||
void help()
|
void help()
|
||||||
{
|
{
|
||||||
|
|
|
@ -671,12 +671,14 @@ nasal_ref builtin_substr(nasal_ref* local,nasal_gc& gc)
|
||||||
return builtin_err("substr","\"begin\" must be number");
|
return builtin_err("substr","\"begin\" must be number");
|
||||||
if(len.type!=vm_num)
|
if(len.type!=vm_num)
|
||||||
return builtin_err("substr","\"length\" must be number");
|
return builtin_err("substr","\"length\" must be number");
|
||||||
int begin=(int)beg.num();
|
if(beg.num()<0)
|
||||||
int length=(int)len.num();
|
return builtin_err("substr","\"begin\" should be greater than or equal to zero");
|
||||||
if(begin>=str.str().length() || begin+length-1>=str.str().length())
|
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");
|
return builtin_err("susbtr","index out of range");
|
||||||
if(length<0)
|
|
||||||
length=0;
|
|
||||||
nasal_ref ret=gc.alloc(vm_str);
|
nasal_ref ret=gc.alloc(vm_str);
|
||||||
ret.str()=str.str().substr(begin,length);
|
ret.str()=str.str().substr(begin,length);
|
||||||
return ret;
|
return ret;
|
||||||
|
|
|
@ -629,7 +629,7 @@ inline void nasal_vm::opr_counter()
|
||||||
}
|
}
|
||||||
inline void nasal_vm::opr_findex()
|
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;
|
pc=imm[pc]-1;
|
||||||
return;
|
return;
|
||||||
|
@ -640,7 +640,7 @@ inline void nasal_vm::opr_findex()
|
||||||
inline void nasal_vm::opr_feach()
|
inline void nasal_vm::opr_feach()
|
||||||
{
|
{
|
||||||
std::vector<nasal_ref>& ref=gc.top[-1].vec().elems;
|
std::vector<nasal_ref>& 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;
|
pc=imm[pc]-1;
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -363,6 +363,8 @@ var math=
|
||||||
pi: 3.14159265358979323846264338327950288,
|
pi: 3.14159265358979323846264338327950288,
|
||||||
inf: 1/0,
|
inf: 1/0,
|
||||||
nan: 0/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); },
|
pow: func(x,y){return __builtin_pow(x,y); },
|
||||||
sin: func(x) {return __builtin_sin(x); },
|
sin: func(x) {return __builtin_sin(x); },
|
||||||
cos: func(x) {return __builtin_cos(x); },
|
cos: func(x) {return __builtin_cos(x); },
|
||||||
|
|
|
@ -198,3 +198,6 @@ println("type\tsize\tnum\tsrc");
|
||||||
foreach(var i;a){
|
foreach(var i;a){
|
||||||
println(typeof(i),'\t',size(i),'\t',num(i),'\t',i);
|
println(typeof(i),'\t',size(i),'\t',num(i),'\t',i);
|
||||||
}
|
}
|
||||||
|
foreach(i;a){
|
||||||
|
;
|
||||||
|
}
|
Loading…
Reference in New Issue