From a13e4195189d730ff1990ce6eecafd4235bbdafd Mon Sep 17 00:00:00 2001 From: ValKmjolnir Date: Sun, 4 Sep 2022 23:08:06 +0800 Subject: [PATCH] :memo: fix MSVC warning in nasal_builtin.h & improve error output. --- module/fib.cpp | 1 - module/keyboard.cpp | 3 +-- module/nasocket.cpp | 1 - nasal.h | 28 +++++++++++++++------------- nasal_builtin.h | 4 ++-- nasal_codegen.h | 12 ++++++------ nasal_lexer.h | 22 +++++++++++----------- nasal_vm.h | 2 +- 8 files changed, 36 insertions(+), 37 deletions(-) diff --git a/module/fib.cpp b/module/fib.cpp index 69cca46..d9ffc30 100644 --- a/module/fib.cpp +++ b/module/fib.cpp @@ -1,6 +1,5 @@ #include #include "../nasal.h" -#include "../nasal_gc.h" double fibonaci(double x){ if(x<=2) diff --git a/module/keyboard.cpp b/module/keyboard.cpp index 81ec122..669d1d3 100644 --- a/module/keyboard.cpp +++ b/module/keyboard.cpp @@ -1,5 +1,4 @@ #include "../nasal.h" -#include "../nasal_gc.h" #include #include #ifdef _WIN32 @@ -63,7 +62,7 @@ public: peek_char=-1; return ch; } - read(0,&ch,1); + ssize_t tmp=read(0,&ch,1); return ch; #else return getch(); diff --git a/module/nasocket.cpp b/module/nasocket.cpp index c8060dd..602b325 100644 --- a/module/nasocket.cpp +++ b/module/nasocket.cpp @@ -1,5 +1,4 @@ #include "../nasal.h" -#include "../nasal_gc.h" #include #ifdef _WIN32 diff --git a/nasal.h b/nasal.h index 9102140..706731e 100644 --- a/nasal.h +++ b/nasal.h @@ -130,19 +130,19 @@ string rawstr(const string& str,const usize maxlen=0) #endif switch(i) { - case '\0': ret+="\\0"; break; - case '\a': ret+="\\a"; break; - case '\b': ret+="\\b"; break; - case '\t': ret+="\\t"; break; - case '\n': ret+="\\n"; break; - case '\v': ret+="\\v"; break; - case '\f': ret+="\\f"; break; - case '\r': ret+="\\r"; break; - case '\033':ret+="\\e";break; - case '\"': ret+="\\\"";break; - case '\'': ret+="\\\'";break; - case '\\': ret+="\\\\";break; - default: ret+=i; break; + case '\0': ret+="\\0"; break; + case '\a': ret+="\\a"; break; + case '\b': ret+="\\b"; break; + case '\t': ret+="\\t"; break; + case '\n': ret+="\\n"; break; + case '\v': ret+="\\v"; break; + case '\f': ret+="\\f"; break; + case '\r': ret+="\\r"; break; + case '\033':ret+="\\e"; break; + case '\"': ret+="\\\"";break; + case '\'': ret+="\\\'";break; + case '\\': ret+="\\\\";break; + default: ret+=i; break; } } if(maxlen && ret.length()>maxlen) @@ -150,4 +150,6 @@ string rawstr(const string& str,const usize maxlen=0) return ret; } +#include "nasal_gc.h" // declarations of nas_ref and nasal_gc + #endif diff --git a/nasal_builtin.h b/nasal_builtin.h index df7f5c7..9714130 100644 --- a/nasal_builtin.h +++ b/nasal_builtin.h @@ -279,11 +279,11 @@ nas_ref builtin_u32or(nas_ref* local,nasal_gc& gc) } nas_ref builtin_u32nand(nas_ref* local,nasal_gc& gc) { - return {vm_num,(f64)(~(u32(local[1].num())&u32(local[2].num())))}; + return {vm_num,(f64)(u32)(~(u32(local[1].num())&u32(local[2].num())))}; } nas_ref builtin_u32not(nas_ref* local,nasal_gc& gc) { - return {vm_num,(f64)(~u32(local[1].num()))}; + return {vm_num,(f64)(u32)(~u32(local[1].num()))}; } nas_ref builtin_pow(nas_ref* local,nasal_gc& gc) { diff --git a/nasal_codegen.h b/nasal_codegen.h index 73ee5cb..81ae647 100644 --- a/nasal_codegen.h +++ b/nasal_codegen.h @@ -436,7 +436,7 @@ void nasal_codegen::func_gen(const nasal_ast& ast) in_iterloop.pop(); code[lsize].num=local.back().size(); if(local.back().size()>=STACK_DEPTH) - die("too many local variants: "+std::to_string(local.back().size())+".",block.line()); + die("too many local variants: "+std::to_string(local.back().size()),block.line()); local.pop_back(); if(!block.size() || block.child().back().type()!=ast_ret) @@ -472,7 +472,7 @@ void nasal_codegen::call_id(const nasal_ast& ast) { gen(op_callb,i,ast.line()); if(local.empty()) - die("builtin functions work in a local scope.",ast.line()); + die("should warp native functions in local scope",ast.line()); return; } i32 index; @@ -491,7 +491,7 @@ void nasal_codegen::call_id(const nasal_ast& ast) gen(op_callg,index,ast.line()); return; } - die("undefined symbol \""+str+"\".",ast.line()); + die("undefined symbol \""+str+"\"",ast.line()); } void nasal_codegen::call_hash(const nasal_ast& ast) @@ -588,7 +588,7 @@ void nasal_codegen::mcall_id(const nasal_ast& ast) for(u32 i=0;builtin[i].name;++i) if(builtin[i].name==str) { - die("cannot change builtin function.",ast.line()); + die("cannot modify native function",ast.line()); return; } i32 index; @@ -607,7 +607,7 @@ void nasal_codegen::mcall_id(const nasal_ast& ast) gen(op_mcallg,index,ast.line()); return; } - die("undefined symbol \""+str+"\".",ast.line()); + die("undefined symbol \""+str+"\"",ast.line()); } void nasal_codegen::mcall_vec(const nasal_ast& ast) @@ -1235,7 +1235,7 @@ void nasal_codegen::compile(const nasal_parse& parse,const nasal_import& import) block_gen(parse.ast()); // generate main block gen(op_exit,0,0); if(global.size()>=STACK_DEPTH) - die("too many global variants: "+std::to_string(global.size())+".",0); + die("too many global variants: "+std::to_string(global.size()),0); nerr.chkerr(); } diff --git a/nasal_lexer.h b/nasal_lexer.h index 68b8ae6..36ca896 100644 --- a/nasal_lexer.h +++ b/nasal_lexer.h @@ -142,12 +142,12 @@ void nasal_lexer::open(const string& file) struct stat buffer; if(stat(file.c_str(),&buffer)==0 && !S_ISREG(buffer.st_mode)) { - nerr.err("lexer","<"+file+"> is not a regular file."); + nerr.err("lexer","<"+file+"> is not a regular file"); nerr.chkerr(); } std::ifstream fin(file,std::ios::binary); if(fin.fail()) - nerr.err("lexer","failed to open <"+file+">."); + nerr.err("lexer","failed to open <"+file+">"); else nerr.load(file); std::stringstream ss; @@ -182,7 +182,7 @@ string nasal_lexer::utf8_gen() string utf_info="0x"+chrhex(tmp[0]); for(u32 i=1;i=res.size()) { - die("get EOF when generating string."); + die("get EOF when generating string"); return str; } ++column; if(begin=='`' && str.length()!=1) - die("\'`\' is used for string that includes one character."); + die("\'`\' is used for string that includes one character"); return str; } @@ -369,7 +369,7 @@ void nasal_lexer::scan(const string& file) ++column; u32 type=get_type(str); if(!type) - die("invalid operator `"+str+"`."); + die("invalid operator `"+str+"`"); tokens.push_back({line,column,type,str}); ++ptr; } @@ -397,7 +397,7 @@ void nasal_lexer::scan(const string& file) { ++column; char c=res[ptr++]; - die("invalid character 0x"+chrhex(c)+"."); + die("invalid character 0x"+chrhex(c)); } } tokens.push_back({line,column,tok_eof,"eof"}); diff --git a/nasal_vm.h b/nasal_vm.h index 787c53a..114fc86 100644 --- a/nasal_vm.h +++ b/nasal_vm.h @@ -880,7 +880,7 @@ inline void nasal_vm::o_mcallv() } } else - die("cannot get memory space in other types"); + die("cannot get memory space in this type"); } inline void nasal_vm::o_mcallh() {