From d72aee62fa517652254d43282de8ef0d4fb63c12 Mon Sep 17 00:00:00 2001 From: ValKmjolnir Date: Sat, 8 Oct 2022 21:34:47 +0800 Subject: [PATCH] :zap: add stl/json.nas & fix bug bug: may cause program crash if stack overflow occurs on main stack --- nasal_dbg.h | 16 +-- nasal_gc.h | 3 +- nasal_vm.h | 1 + stl/json.nas | 268 ++++++++++++++++++++++++++++++++++++++++++ test/calc.nas | 1 + test/coroutine.nas | 46 +++++--- test/json.nas | 276 +------------------------------------------- test/md5compare.nas | 1 + 8 files changed, 314 insertions(+), 298 deletions(-) create mode 100644 stl/json.nas diff --git a/nasal_dbg.h b/nasal_dbg.h index 2d2a197..88f529a 100644 --- a/nasal_dbg.h +++ b/nasal_dbg.h @@ -301,14 +301,12 @@ void nasal_dbg::run( ++count[code[pc]]; (this->*oprs[code[pc]])(); if(top>=canary) - break; + die("stack overflow"); ++pc; } #endif vmexit: - if(top>=canary) - die("stack overflow"); callsort(count); gc.clear(); imm.clear(); @@ -316,12 +314,14 @@ vmexit: return; #ifndef _MSC_VER #define dbg(op,num) {\ - interact();\ - op();\ - ++count[num];\ - if(top=text_size){ + token.content="eof"; + token.type=j_eof; + return; + } + + var c=text[ptr]; + if(c=='{'){ + token.content='{'; + token.type=j_lbrace; + }elsif(c=='}'){ + token.content='}'; + token.type=j_rbrace; + }elsif(c=='['){ + token.content='['; + token.type=j_lbracket; + }elsif(c==']'){ + token.content=']'; + token.type=j_rbracket; + }elsif(c==','){ + token.content=','; + token.type=j_comma; + }elsif(c==':'){ + token.content=':'; + token.type=j_colon; + }elsif(c=='\"' or c=='\''){ + var strbegin=c; + var s=""; + ptr+=1; + while(ptr=text_size){ - token.content="eof"; - token.type=j_eof; - return; - } - - var c=text[ptr]; - if(c=='{'){ - token.content='{'; - token.type=j_lbrace; - }elsif(c=='}'){ - token.content='}'; - token.type=j_rbrace; - }elsif(c=='['){ - token.content='['; - token.type=j_lbracket; - }elsif(c==']'){ - token.content=']'; - token.type=j_rbracket; - }elsif(c==','){ - token.content=','; - token.type=j_comma; - }elsif(c==':'){ - token.content=':'; - token.type=j_colon; - }elsif(c=='\"' or c=='\''){ - var strbegin=c; - var s=""; - ptr+=1; - while(ptr