📝 rename nasal_builtin.*

This commit is contained in:
ValKmjolnir 2024-06-02 16:06:18 +08:00
parent 2c6a0fd84d
commit a7dfd34120
21 changed files with 66 additions and 70 deletions

View File

@ -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

View File

@ -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__

View File

@ -26,11 +26,9 @@
__如果有好的意见或建议欢迎联系我们!__
* __E-mail__:
* __lhk101lhk101@qq.com__ (ValKmjolnir)
* __lhk101lhk101@qq.com__ (ValKmjolnir)
* __1467329765@qq.com__(Sidi762)
* __sidi.liang@gmail.com__ (Sidi)
## __简介__

View File

@ -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

View File

@ -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"

View File

@ -1,7 +1,7 @@
#pragma once
#include "nasal.h"
#include "natives/nasal_builtin.h"
#include "natives/builtin.h"
#include <iostream>

View File

@ -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();
}

View File

@ -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();

View File

@ -2,7 +2,7 @@
#include "nasal.h"
#include "nasal_gc.h"
#include "natives/nasal_builtin.h"
#include "natives/builtin.h"
namespace nasal {

View File

@ -1,4 +1,4 @@
#include "natives/nasal_builtin.h"
#include "natives/builtin.h"
#include <chrono>
#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<u32>(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<time_t>(val.num());
return var::num(static_cast<f64>(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<usize>(beg.num());
auto length = static_cast<usize>(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<i32>(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<f64>(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();

View File

@ -2,7 +2,7 @@
#include "nasal.h"
#include "nasal_gc.h"
#include "natives/nasal_builtin.h"
#include "natives/builtin.h"
namespace nasal {

View File

@ -2,7 +2,7 @@
#include "nasal.h"
#include "nasal_gc.h"
#include "natives/nasal_builtin.h"
#include "natives/builtin.h"
#ifdef _WIN32
#include <windows.h>

View File

@ -2,7 +2,7 @@
#include "nasal.h"
#include "nasal_gc.h"
#include "natives/nasal_builtin.h"
#include "natives/builtin.h"
namespace nasal {

View File

@ -2,7 +2,7 @@
#include "nasal.h"
#include "nasal_gc.h"
#include "natives/nasal_builtin.h"
#include "natives/builtin.h"
#ifndef _MSC_VER
#include <unistd.h>

View File

@ -2,7 +2,7 @@
#include "nasal.h"
#include "nasal_gc.h"
#include "natives/nasal_builtin.h"
#include "natives/builtin.h"
namespace nasal {

View File

@ -2,7 +2,7 @@
#include "nasal.h"
#include "nasal_gc.h"
#include "natives/nasal_builtin.h"
#include "natives/builtin.h"
namespace nasal {

View File

@ -4,7 +4,7 @@
#include "nasal.h"
#include "nasal_gc.h"
#include "natives/nasal_builtin.h"
#include "natives/builtin.h"
namespace nasal {

View File

@ -2,7 +2,7 @@
#include "nasal.h"
#include "nasal_gc.h"
#include "natives/nasal_builtin.h"
#include "natives/builtin.h"
#ifndef _MSC_VER
#include <unistd.h>

View File

@ -3,6 +3,23 @@ use std.process_bar;
use std.unix;
use std.runtime;
var table_character_set = [
"─", "━", "│", "┃", "╌", "╍", "╎", "╏", "┄", "┅",
"┆", "┇", "┈", "┉", "┊", "┋", "┌", "┍", "┎", "┏",
"┐", "┑", "┒", "┓", "└", "┕", "┖", "┗", "┘", "┙",
"┚", "┛", "├", "┝", "┞", "┟", "┠", "┡", "┢", "┣",
"┤", "┥", "┦", "┧", "┨", "┩", "┪", "┫", "┬", "┭",
"┮", "┯", "┰", "┱", "┲", "┳", "┴", "┵", "┶", "┷",
"┸", "┹", "┺", "┻", "┼", "┽", "┾", "┿", "╀", "╁",
"╂", "╃", "╄", "╅", "╆", "╇", "╈", "╉", "╊", "╋",
"╪", "╫", "╬", "═", "║", "╒", "╓", "╔", "╕", "╖",
"╗", "╘", "╙", "╚", "╛", "╜", "╝", "╞", "╟", "╠",
"╡", "╢", "╣", "╤", "╥", "╦", "╧", "╨", "╬", "╩",
"┷", "┳", "⊥", "﹃", "﹄", "╮", "╭", "╯", "╰", ""
];
var selection_box = ["○", "◉", "☐", "▣"];
var char_ttf=[
[" "," "," "," "," "," "],
[" █████╗ ","██╔══██╗","███████║","██╔══██║","██║ ██║","╚═╝ ╚═╝"],

View File

@ -2,23 +2,6 @@ use std.runtime;
runtime.windows.set_utf8_output();
var table_character_set = [
"─", "━", "│", "┃", "╌", "╍", "╎", "╏", "┄", "┅",
"┆", "┇", "┈", "┉", "┊", "┋", "┌", "┍", "┎", "┏",
"┐", "┑", "┒", "┓", "└", "┕", "┖", "┗", "┘", "┙",
"┚", "┛", "├", "┝", "┞", "┟", "┠", "┡", "┢", "┣",
"┤", "┥", "┦", "┧", "┨", "┩", "┪", "┫", "┬", "┭",
"┮", "┯", "┰", "┱", "┲", "┳", "┴", "┵", "┶", "┷",
"┸", "┹", "┺", "┻", "┼", "┽", "┾", "┿", "╀", "╁",
"╂", "╃", "╄", "╅", "╆", "╇", "╈", "╉", "╊", "╋",
"╪", "╫", "╬", "═", "║", "╒", "╓", "╔", "╕", "╖",
"╗", "╘", "╙", "╚", "╛", "╜", "╝", "╞", "╟", "╠",
"╡", "╢", "╣", "╤", "╥", "╦", "╧", "╨", "╩", "╔",
"╗", "╝", "╚", "╬", "═", "╓", "╩", "┠", "┨", "┯",
"┷", "┏", "┓", "┗", "┛", "┳", "⊥", "﹃", "﹄",
"╮", "╭", "╯", "╰", ""
];
var road_enum = {
null: 0,
narrow: 1,