From 1f43eae4fabc86ea94feadaf5293707ac61f5d43 Mon Sep 17 00:00:00 2001 From: ValKmjolnir Date: Wed, 15 May 2024 22:59:36 +0800 Subject: [PATCH] :fire: expand stack depth to 65535 --- src/nasal.h | 2 +- src/nasal_codegen.cpp | 4 ++-- src/nasal_codegen.h | 4 ++-- src/nasal_lexer.h | 4 ++-- src/nasal_parse.cpp | 16 ++++++++-------- src/nasal_parse.h | 2 +- src/nasal_type.cpp | 4 ++-- src/nasal_type.h | 2 +- src/nasal_vm.cpp | 6 +++--- src/nasal_vm.h | 4 ++-- 10 files changed, 24 insertions(+), 24 deletions(-) diff --git a/src/nasal.h b/src/nasal.h index 0c59625..225ee82 100644 --- a/src/nasal.h +++ b/src/nasal.h @@ -38,7 +38,7 @@ const char* get_platform(); const char* get_arch(); // virtual machine stack depth, both global depth and value stack depth -const u32 STACK_DEPTH = 4096; +const u32 VM_STACK_DEPTH = UINT16_MAX; f64 hex_to_f64(const char*); f64 oct_to_f64(const char*); diff --git a/src/nasal_codegen.cpp b/src/nasal_codegen.cpp index 86fb620..ab5e42e 100644 --- a/src/nasal_codegen.cpp +++ b/src/nasal_codegen.cpp @@ -309,7 +309,7 @@ void codegen::func_gen(function* node) { // the local scope should not cause stack overflow // and should not greater than upvalue's max size(65536) code[lsize].num = local.back().size(); - if (local.back().size()>=STACK_DEPTH || local.back().size()>=UINT16_MAX) { + if (local.back().size()>=VM_STACK_DEPTH || local.back().size()>=UINT16_MAX) { die("too many local variants: " + std::to_string(local.back().size()), block->get_location() @@ -1361,7 +1361,7 @@ const error& codegen::compile(parse& parse, } // check global variables size - if (global.size()>=STACK_DEPTH/2) { + if (global.size()>=VM_STACK_DEPTH) { err.err("code", "too many global variables: " + std::to_string(global.size()) diff --git a/src/nasal_codegen.h b/src/nasal_codegen.h index e171f83..2b4ba53 100644 --- a/src/nasal_codegen.h +++ b/src/nasal_codegen.h @@ -87,7 +87,7 @@ private: std::list> break_ptr; // symbol table - // global : max STACK_DEPTH-1 values + // global : max VM_STACK_DEPTH-1 values std::unordered_map global; // nasal namespace @@ -95,7 +95,7 @@ private: std::unordered_map> nasal_namespace; // local : max 32768 upvalues 65536 values - // but in fact local scope also has less than STACK_DEPTH value + // but in fact local scope also has less than VM_STACK_DEPTH value std::list> local; void check_id_exist(identifier*); diff --git a/src/nasal_lexer.h b/src/nasal_lexer.h index a37ebe4..461b03d 100644 --- a/src/nasal_lexer.h +++ b/src/nasal_lexer.h @@ -36,7 +36,7 @@ enum class tok:u32 { rif, // condition expression keyword if elsif, // condition expression keyword elsif relse, // condition expression keyword else - tknil, // nil literal + nil, // nil literal lcurve, // ( rcurve, // ) lbracket, // [ @@ -114,7 +114,7 @@ private: {"if" ,tok::rif }, {"elsif" ,tok::elsif }, {"else" ,tok::relse }, - {"nil" ,tok::tknil }, + {"nil" ,tok::nil }, {"(" ,tok::lcurve }, {")" ,tok::rcurve }, {"[" ,tok::lbracket}, diff --git a/src/nasal_parse.cpp b/src/nasal_parse.cpp index 8bc0159..163c9bb 100644 --- a/src/nasal_parse.cpp +++ b/src/nasal_parse.cpp @@ -256,7 +256,7 @@ vector_expr* parse::vec() { // array end with tok::null=0 const tok panic[] = { tok::id, tok::str, tok::num, tok::tktrue, - tok::tkfalse, tok::opnot, tok::sub, tok::tknil, + tok::tkfalse, tok::opnot, tok::sub, tok::nil, tok::func, tok::var, tok::lcurve, tok::floater, tok::lbrace, tok::lbracket, tok::null }; @@ -372,7 +372,7 @@ expr* parse::expression() { } switch(type) { case tok::use: return use_stmt_gen(); - case tok::tknil: + case tok::nil: case tok::num: case tok::str: case tok::id: @@ -637,9 +637,9 @@ unary_operator* parse::unary() { expr* parse::scalar() { expr* node = nullptr; - if (lookahead(tok::tknil)) { + if (lookahead(tok::nil)) { node = nil(); - match(tok::tknil); + match(tok::nil); } else if (lookahead(tok::num)) { node = num(); } else if (lookahead(tok::str)) { @@ -715,7 +715,7 @@ call_vector* parse::callv() { // array end with tok::null=0 const tok panic[] = { tok::id, tok::str, tok::num, tok::tktrue, - tok::tkfalse, tok::opnot, tok::sub, tok::tknil, + tok::tkfalse, tok::opnot, tok::sub, tok::nil, tok::func, tok::var, tok::lcurve, tok::floater, tok::lbrace, tok::lbracket, tok::colon, tok::null }; @@ -745,7 +745,7 @@ call_function* parse::callf() { // array end with tok::null=0 const tok panic[] = { tok::id, tok::str, tok::num, tok::tktrue, - tok::tkfalse, tok::opnot, tok::sub, tok::tknil, + tok::tkfalse, tok::opnot, tok::sub, tok::nil, tok::func, tok::var, tok::lcurve, tok::floater, tok::lbrace, tok::lbracket, tok::null }; @@ -844,7 +844,7 @@ tuple_expr* parse::multi_scalar() { // we will check if value called here can reach a memory space const tok panic[] = { tok::id, tok::str, tok::num, tok::tktrue, - tok::tkfalse, tok::opnot, tok::sub, tok::tknil, + tok::tkfalse, tok::opnot, tok::sub, tok::nil, tok::func, tok::var, tok::lcurve, tok::floater, tok::lbrace, tok::lbracket, tok::null }; @@ -1070,7 +1070,7 @@ return_expr* parse::return_expression() { auto node = new return_expr(toks[ptr].loc); match(tok::ret); tok type = toks[ptr].type; - if (type==tok::tknil || type==tok::num || + if (type==tok::nil || type==tok::num || type==tok::str || type==tok::id || type==tok::func || type==tok::sub || type==tok::opnot || type==tok::lcurve || diff --git a/src/nasal_parse.h b/src/nasal_parse.h index 2d8ff27..85d351c 100644 --- a/src/nasal_parse.h +++ b/src/nasal_parse.h @@ -37,7 +37,7 @@ private: {tok::rif ,"if" }, {tok::elsif ,"elsif" }, {tok::relse ,"else" }, - {tok::tknil ,"nil" }, + {tok::nil ,"nil" }, {tok::lcurve ,"(" }, {tok::rcurve ,")" }, {tok::lbracket,"[" }, diff --git a/src/nasal_type.cpp b/src/nasal_type.cpp index 693bc15..91feb10 100644 --- a/src/nasal_type.cpp +++ b/src/nasal_type.cpp @@ -171,14 +171,14 @@ void nas_co::clear() { if (!ctx.stack) { return; } - for(u32 i = 0; i