mirror of
https://github.com/ValKmjolnir/Nasal-Interpreter.git
synced 2026-07-21 18:38:44 +08:00
🐛 bug fix
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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); },
|
||||
|
||||
@@ -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"
|
||||
|
||||
+7
-5
@@ -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;
|
||||
|
||||
+2
-2
@@ -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<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;
|
||||
return;
|
||||
|
||||
@@ -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); },
|
||||
|
||||
@@ -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){
|
||||
;
|
||||
}
|
||||
Reference in New Issue
Block a user