diff --git a/CMakeLists.txt b/CMakeLists.txt index cbecc8d..00f7218 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -17,7 +17,7 @@ set(CMAKE_BUILD_TYPE "Release") # build nasal used object set(NASAL_OBJECT_SOURCE_FILE ${CMAKE_SOURCE_DIR}/src/cli/cli.cpp - ${CMAKE_SOURCE_DIR}/src/natives/nasal_builtin.cpp + ${CMAKE_SOURCE_DIR}/src/natives/builtin.cpp ${CMAKE_SOURCE_DIR}/src/natives/coroutine.cpp ${CMAKE_SOURCE_DIR}/src/natives/fg_props.cpp ${CMAKE_SOURCE_DIR}/src/natives/bits_lib.cpp diff --git a/README.md b/README.md index e8b5158..df1701f 100644 --- a/README.md +++ b/README.md @@ -26,11 +26,9 @@ __Contact us if having great ideas to share!__ -* __E-mail__: +* __lhk101lhk101@qq.com__ (ValKmjolnir) - * __lhk101lhk101@qq.com__ (ValKmjolnir) - - * __sidi.liang@gmail.com__ (Sidi) +* __sidi.liang@gmail.com__ (Sidi) ## __Introduction__ diff --git a/doc/README_zh.md b/doc/README_zh.md index 0cdd1da..c5b0831 100644 --- a/doc/README_zh.md +++ b/doc/README_zh.md @@ -26,11 +26,9 @@ __如果有好的意见或建议,欢迎联系我们!__ -* __E-mail__: +* __lhk101lhk101@qq.com__ (ValKmjolnir) - * __lhk101lhk101@qq.com__ (ValKmjolnir) - - * __1467329765@qq.com__(Sidi762) +* __sidi.liang@gmail.com__ (Sidi) ## __简介__ diff --git a/makefile b/makefile index a496739..12b42a1 100644 --- a/makefile +++ b/makefile @@ -13,7 +13,7 @@ NASAL_HEADER = \ src/ast_dumper.h\ src/ast_visitor.h\ src/nasal_ast.h\ - src/natives/nasal_builtin.h\ + src/natives/builtin.h\ src/nasal_codegen.h\ src/nasal_dbg.h\ src/nasal_err.h\ @@ -54,7 +54,7 @@ NASAL_OBJECT = \ build/nasal_codegen.o\ build/nasal_misc.o\ build/nasal_gc.o\ - build/nasal_builtin.o\ + build/builtin.o\ build/fg_props.o\ build/io_lib.o\ build/math_lib.o\ @@ -127,12 +127,12 @@ build/nasal_ast.o: \ src/nasal_ast.h src/nasal_ast.cpp | build $(CXX) $(CXXFLAGS) src/nasal_ast.cpp -o build/nasal_ast.o -build/nasal_builtin.o: \ +build/builtin.o: \ src/nasal.h\ src/nasal_type.h\ src/nasal_gc.h\ - src/natives/nasal_builtin.h src/natives/nasal_builtin.cpp | build - $(CXX) $(CXXFLAGS) src/natives/nasal_builtin.cpp -o build/nasal_builtin.o + src/natives/builtin.h src/natives/builtin.cpp | build + $(CXX) $(CXXFLAGS) src/natives/builtin.cpp -o build/builtin.o build/coroutine.o: \ src/nasal.h\ @@ -203,7 +203,7 @@ build/nasal_codegen.o: $(NASAL_HEADER) src/nasal_codegen.h src/nasal_codegen.cpp build/nasal_opcode.o: \ src/nasal.h\ - src/natives/nasal_builtin.h\ + src/natives/builtin.h\ src/nasal_opcode.h src/nasal_opcode.cpp | build $(CXX) $(CXXFLAGS) src/nasal_opcode.cpp -o build/nasal_opcode.o diff --git a/src/nasal_codegen.h b/src/nasal_codegen.h index 2b4ba53..8501426 100644 --- a/src/nasal_codegen.h +++ b/src/nasal_codegen.h @@ -8,7 +8,7 @@ #include "nasal_parse.h" #include "nasal_import.h" -#include "natives/nasal_builtin.h" +#include "natives/builtin.h" #include "natives/coroutine.h" #include "natives/bits_lib.h" #include "natives/math_lib.h" diff --git a/src/nasal_opcode.h b/src/nasal_opcode.h index fd2502c..55e81c8 100644 --- a/src/nasal_opcode.h +++ b/src/nasal_opcode.h @@ -1,7 +1,7 @@ #pragma once #include "nasal.h" -#include "natives/nasal_builtin.h" +#include "natives/builtin.h" #include diff --git a/src/nasal_type.cpp b/src/nasal_type.cpp index 91feb10..cdb6b38 100644 --- a/src/nasal_type.cpp +++ b/src/nasal_type.cpp @@ -384,7 +384,7 @@ nas_map& var::map() { } var nas_err(const std::string& error_function_name, const std::string& info) { - std::cerr << "\n[vm] " << error_function_name << ": " << info << "\n"; + std::cerr << "[vm] " << error_function_name << ": " << info << "\n"; return var::none(); } diff --git a/src/nasal_vm.cpp b/src/nasal_vm.cpp index f5d205a..abf9454 100644 --- a/src/nasal_vm.cpp +++ b/src/nasal_vm.cpp @@ -75,8 +75,8 @@ void vm::value_info(var& val) { case vm_type::vm_nil: std::clog << "| nil |"; break; case vm_type::vm_num: std::clog << "| num | " << val.num(); break; case vm_type::vm_str: std::clog << "| str | <0x" << std::hex << p - << "> " << rawstr(val.str(), 16) - << std::dec; break; + << "> \"" << rawstr(val.str(), 16) + << "\"" << std::dec; break; case vm_type::vm_func: std::clog << "| func | <0x" << std::hex << p << std::dec << "> " << val.func(); break; @@ -391,7 +391,7 @@ std::string vm::type_name_string(const var& value) const { } void vm::die(const std::string& str) { - std::cerr << "\n[vm] error: " << str << "\n"; + std::cerr << "[vm] error: " << str << "\n"; function_call_trace(); trace_back(); stack_info(); diff --git a/src/natives/bits_lib.h b/src/natives/bits_lib.h index 49f160d..a1673bb 100644 --- a/src/natives/bits_lib.h +++ b/src/natives/bits_lib.h @@ -2,7 +2,7 @@ #include "nasal.h" #include "nasal_gc.h" -#include "natives/nasal_builtin.h" +#include "natives/builtin.h" namespace nasal { diff --git a/src/natives/nasal_builtin.cpp b/src/natives/builtin.cpp similarity index 89% rename from src/natives/nasal_builtin.cpp rename to src/natives/builtin.cpp index d9beaba..39da951 100644 --- a/src/natives/nasal_builtin.cpp +++ b/src/natives/builtin.cpp @@ -1,4 +1,4 @@ -#include "natives/nasal_builtin.h" +#include "natives/builtin.h" #include #ifdef _WIN32 @@ -45,7 +45,7 @@ var builtin_append(context* ctx, gc* ngc) { var vec = local[1]; var elem = local[2]; if (!vec.is_vec()) { - return nas_err("append", "\"vec\" must be vector"); + return nas_err("native::append", "\"vec\" must be vector"); } auto& v = vec.vec().elems; for(auto& i : elem.vec().elems) { @@ -59,7 +59,7 @@ var builtin_setsize(context* ctx, gc* ngc) { var vec = local[1]; var size = local[2]; if (!vec.is_vec()) { - return nas_err("setsize", "\"vec\" must be vector"); + return nas_err("native::setsize", "\"vec\" must be vector"); } if (!size.is_num() || size.num()<0) { return nil; @@ -93,10 +93,10 @@ var builtin_split(context* ctx, gc* ngc) { var delimeter = local[1]; var str = local[2]; if (!delimeter.is_str()) { - return nas_err("split", "\"separator\" must be string"); + return nas_err("native::split", "\"separator\" must be string"); } if (!str.is_str()) { - return nas_err("split", "\"str\" must be string"); + return nas_err("native::split", "\"str\" must be string"); } const auto& deli = delimeter.str(); const auto& s = str.str(); @@ -131,7 +131,7 @@ var builtin_split(context* ctx, gc* ngc) { var builtin_rand(context* ctx, gc* ngc) { auto val = ctx->localr[1]; if (!val.is_num() && !val.is_nil()) { - return nas_err("rand", "\"seed\" must be nil or number"); + return nas_err("native::rand", "\"seed\" must be nil or number"); } if (val.is_num()) { srand(static_cast(val.num())); @@ -191,7 +191,7 @@ var builtin_num(context* ctx, gc* ngc) { var builtin_pop(context* ctx, gc* ngc) { auto val = ctx->localr[1]; if (!val.is_vec()) { - return nas_err("pop", "\"vec\" must be vector"); + return nas_err("native::pop", "\"vec\" must be vector"); } auto& vec = val.vec().elems; if (vec.size()) { @@ -224,7 +224,7 @@ var builtin_size(context* ctx, gc* ngc) { var builtin_time(context* ctx, gc* ngc) { auto val = ctx->localr[1]; if (!val.is_num()) { - return nas_err("time", "\"begin\" must be number"); + return nas_err("native::time", "\"begin\" must be number"); } auto begin = static_cast(val.num()); return var::num(static_cast(time(&begin))); @@ -245,7 +245,7 @@ var builtin_delete(context* ctx, gc* ngc) { var hash = local[1]; var key = local[2]; if (!hash.is_hash()) { - return nas_err("delete", "\"hash\" must be hash"); + return nas_err("native::delete", "\"hash\" must be hash"); } if (!key.is_str()) { return nil; @@ -259,7 +259,7 @@ var builtin_delete(context* ctx, gc* ngc) { var builtin_keys(context* ctx, gc* ngc) { auto hash = ctx->localr[1]; if (!hash.is_hash() && !hash.is_map()) { - return nas_err("keys", "\"hash\" must be hash"); + return nas_err("native::keys", "\"hash\" must be hash"); } // avoid being sweeped auto res = ngc->temp = ngc->alloc(vm_type::vm_vec); @@ -278,7 +278,7 @@ var builtin_keys(context* ctx, gc* ngc) { } var builtin_die(context* ctx, gc* ngc) { - return nas_err("error", ctx->localr[1].to_str()); + return nas_err("native::error", ctx->localr[1].to_str()); } var builtin_find(context* ctx, gc* ngc) { @@ -315,18 +315,18 @@ var builtin_substr(context* ctx, gc* ngc) { var beg = local[2]; var len = local[3]; if (!str.is_str()) { - return nas_err("substr", "\"str\" must be string"); + return nas_err("native::substr", "\"str\" must be string"); } if (!beg.is_num() || beg.num()<0) { - return nas_err("substr", "\"begin\" should be number >= 0"); + return nas_err("native::substr", "\"begin\" should be number >= 0"); } if (!len.is_num() || len.num()<0) { - return nas_err("substr", "\"length\" should be number >= 0"); + return nas_err("native::substr", "\"length\" should be number >= 0"); } auto begin = static_cast(beg.num()); auto length = static_cast(len.num()); if (begin>=str.str().length()) { - return nas_err("susbtr", "begin index out of range: "+std::to_string(begin)); + return nas_err("native::susbtr", "begin index out of range: "+std::to_string(begin)); } return ngc->newstr(str.str().substr(begin, length)); } @@ -346,10 +346,10 @@ var builtin_left(context* ctx, gc* ngc) { var len = local[2]; if (!str.is_str()) { - return nas_err("left", "\"string\" must be string"); + return nas_err("native::left", "\"string\" must be string"); } if (!len.is_num()) { - return nas_err("left", "\"length\" must be number"); + return nas_err("native::left", "\"length\" must be number"); } if (len.num()<0) { return ngc->newstr(""); @@ -363,10 +363,10 @@ var builtin_right(context* ctx, gc* ngc) { var len = local[2]; if (!str.is_str()) { - return nas_err("right", "\"string\" must be string"); + return nas_err("native::right", "\"string\" must be string"); } if (!len.is_num()) { - return nas_err("right", "\"length\" must be number"); + return nas_err("native::right", "\"length\" must be number"); } i32 length = static_cast(len.num()); @@ -386,7 +386,7 @@ var builtin_cmp(context* ctx, gc* ngc) { var a = local[1]; var b = local[2]; if (!a.is_str() || !b.is_str()) { - return nas_err("cmp", "\"a\" and \"b\" must be string"); + return nas_err("native::cmp", "\"a\" and \"b\" must be string"); } return var::num(static_cast(strcmp( a.str().c_str(), @@ -429,7 +429,7 @@ var builtin_char(context* ctx, gc* ngc) { var builtin_values(context* ctx, gc* ngc) { auto hash = ctx->localr[1]; if (!hash.is_hash() && !hash.is_map()) { - return nas_err("values", "\"hash\" must be hash or namespace"); + return nas_err("native::values", "\"hash\" must be hash or namespace"); } auto vec = ngc->alloc(vm_type::vm_vec); auto& v = vec.vec().elems; @@ -564,7 +564,7 @@ std::string md5(const std::string& src) { var builtin_md5(context* ctx, gc* ngc) { auto str = ctx->localr[1]; if (!str.is_str()) { - return nas_err("md5", "\"str\" must be string"); + return nas_err("native::md5", "\"str\" must be string"); } return ngc->newstr(md5(str.str())); } @@ -704,7 +704,7 @@ var builtin_logtime(context* ctx, gc* ngc) { var builtin_ghosttype(context* ctx, gc* ngc) { auto arg = ctx->localr[1]; if (!arg.is_ghost()) { - return nas_err("ghosttype", "this is not a ghost object."); + return nas_err("native::ghosttype", "this is not a ghost object."); } const auto& name = arg.ghost().get_ghost_name(); diff --git a/src/natives/nasal_builtin.h b/src/natives/builtin.h similarity index 100% rename from src/natives/nasal_builtin.h rename to src/natives/builtin.h diff --git a/src/natives/coroutine.h b/src/natives/coroutine.h index 7760e34..d0327d6 100644 --- a/src/natives/coroutine.h +++ b/src/natives/coroutine.h @@ -2,7 +2,7 @@ #include "nasal.h" #include "nasal_gc.h" -#include "natives/nasal_builtin.h" +#include "natives/builtin.h" namespace nasal { diff --git a/src/natives/dylib_lib.h b/src/natives/dylib_lib.h index 0998cba..3b49dea 100644 --- a/src/natives/dylib_lib.h +++ b/src/natives/dylib_lib.h @@ -2,7 +2,7 @@ #include "nasal.h" #include "nasal_gc.h" -#include "natives/nasal_builtin.h" +#include "natives/builtin.h" #ifdef _WIN32 #include diff --git a/src/natives/fg_props.h b/src/natives/fg_props.h index 07bfdcf..a692169 100644 --- a/src/natives/fg_props.h +++ b/src/natives/fg_props.h @@ -2,7 +2,7 @@ #include "nasal.h" #include "nasal_gc.h" -#include "natives/nasal_builtin.h" +#include "natives/builtin.h" namespace nasal { diff --git a/src/natives/io_lib.h b/src/natives/io_lib.h index 6b3f6ea..3f2937f 100644 --- a/src/natives/io_lib.h +++ b/src/natives/io_lib.h @@ -2,7 +2,7 @@ #include "nasal.h" #include "nasal_gc.h" -#include "natives/nasal_builtin.h" +#include "natives/builtin.h" #ifndef _MSC_VER #include diff --git a/src/natives/json_lib.h b/src/natives/json_lib.h index ad4fc86..830a121 100644 --- a/src/natives/json_lib.h +++ b/src/natives/json_lib.h @@ -2,7 +2,7 @@ #include "nasal.h" #include "nasal_gc.h" -#include "natives/nasal_builtin.h" +#include "natives/builtin.h" namespace nasal { diff --git a/src/natives/math_lib.h b/src/natives/math_lib.h index 92dcd65..c6df825 100644 --- a/src/natives/math_lib.h +++ b/src/natives/math_lib.h @@ -2,7 +2,7 @@ #include "nasal.h" #include "nasal_gc.h" -#include "natives/nasal_builtin.h" +#include "natives/builtin.h" namespace nasal { diff --git a/src/natives/regex_lib.h b/src/natives/regex_lib.h index ba0ceff..5e471f5 100644 --- a/src/natives/regex_lib.h +++ b/src/natives/regex_lib.h @@ -4,7 +4,7 @@ #include "nasal.h" #include "nasal_gc.h" -#include "natives/nasal_builtin.h" +#include "natives/builtin.h" namespace nasal { diff --git a/src/natives/unix_lib.h b/src/natives/unix_lib.h index 40d7d49..93a70aa 100644 --- a/src/natives/unix_lib.h +++ b/src/natives/unix_lib.h @@ -2,7 +2,7 @@ #include "nasal.h" #include "nasal_gc.h" -#include "natives/nasal_builtin.h" +#include "natives/builtin.h" #ifndef _MSC_VER #include diff --git a/test/ascii-art.nas b/test/ascii-art.nas index ce654a6..574c912 100644 --- a/test/ascii-art.nas +++ b/test/ascii-art.nas @@ -3,6 +3,23 @@ use std.process_bar; use std.unix; use std.runtime; +var table_character_set = [ + "─", "━", "│", "┃", "╌", "╍", "╎", "╏", "┄", "┅", + "┆", "┇", "┈", "┉", "┊", "┋", "┌", "┍", "┎", "┏", + "┐", "┑", "┒", "┓", "└", "┕", "┖", "┗", "┘", "┙", + "┚", "┛", "├", "┝", "┞", "┟", "┠", "┡", "┢", "┣", + "┤", "┥", "┦", "┧", "┨", "┩", "┪", "┫", "┬", "┭", + "┮", "┯", "┰", "┱", "┲", "┳", "┴", "┵", "┶", "┷", + "┸", "┹", "┺", "┻", "┼", "┽", "┾", "┿", "╀", "╁", + "╂", "╃", "╄", "╅", "╆", "╇", "╈", "╉", "╊", "╋", + "╪", "╫", "╬", "═", "║", "╒", "╓", "╔", "╕", "╖", + "╗", "╘", "╙", "╚", "╛", "╜", "╝", "╞", "╟", "╠", + "╡", "╢", "╣", "╤", "╥", "╦", "╧", "╨", "╬", "╩", + "┷", "┳", "⊥", "﹃", "﹄", "╮", "╭", "╯", "╰", "╳" +]; + +var selection_box = ["○", "◉", "☐", "▣"]; + var char_ttf=[ [" "," "," "," "," "," "], [" █████╗ ","██╔══██╗","███████║","██╔══██║","██║ ██║","╚═╝ ╚═╝"], diff --git a/test/wavecity.nas b/test/wavecity.nas index 4484796..89d085b 100644 --- a/test/wavecity.nas +++ b/test/wavecity.nas @@ -2,23 +2,6 @@ use std.runtime; runtime.windows.set_utf8_output(); -var table_character_set = [ - "─", "━", "│", "┃", "╌", "╍", "╎", "╏", "┄", "┅", - "┆", "┇", "┈", "┉", "┊", "┋", "┌", "┍", "┎", "┏", - "┐", "┑", "┒", "┓", "└", "┕", "┖", "┗", "┘", "┙", - "┚", "┛", "├", "┝", "┞", "┟", "┠", "┡", "┢", "┣", - "┤", "┥", "┦", "┧", "┨", "┩", "┪", "┫", "┬", "┭", - "┮", "┯", "┰", "┱", "┲", "┳", "┴", "┵", "┶", "┷", - "┸", "┹", "┺", "┻", "┼", "┽", "┾", "┿", "╀", "╁", - "╂", "╃", "╄", "╅", "╆", "╇", "╈", "╉", "╊", "╋", - "╪", "╫", "╬", "═", "║", "╒", "╓", "╔", "╕", "╖", - "╗", "╘", "╙", "╚", "╛", "╜", "╝", "╞", "╟", "╠", - "╡", "╢", "╣", "╤", "╥", "╦", "╧", "╨", "╩", "╔", - "╗", "╝", "╚", "╬", "═", "╓", "╩", "┠", "┨", "┯", - "┷", "┏", "┓", "┗", "┛", "┳", "⊥", "﹃", "﹄", - "╮", "╭", "╯", "╰", "╳" -]; - var road_enum = { null: 0, narrow: 1,