📝 change span data from u32 to u64
This commit is contained in:
parent
eed59cfe07
commit
8e38764df0
|
@ -2,7 +2,6 @@
|
|||
|
||||
<img src="./doc/pic/header.png" style="width:600px"></img>
|
||||
|
||||

|
||||

|
||||
[](./LICENSE)
|
||||

|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
|
||||
<img src="../doc/pic/header.png" style="width:600px"></img>
|
||||
|
||||

|
||||

|
||||
[](../LICENSE)
|
||||

|
||||
|
|
|
@ -53,7 +53,9 @@ struct ghost_obj {
|
|||
void ghost_for_test_destructor(void* ptr) {
|
||||
std::cout << "ghost_for_test::destructor (0x";
|
||||
std::cout << std::hex << reinterpret_cast<u64>(ptr) << std::dec << ") {\n";
|
||||
|
||||
delete static_cast<ghost_obj*>(ptr);
|
||||
|
||||
std::cout << " delete 0x" << std::hex;
|
||||
std::cout << reinterpret_cast<u64>(ptr) << std::dec << ";\n";
|
||||
std::cout << "}\n";
|
||||
|
@ -62,7 +64,9 @@ void ghost_for_test_destructor(void* ptr) {
|
|||
void ghost_for_test_gc_marker(void* ptr, std::vector<var>* bfs_queue) {
|
||||
std::cout << "ghost_for_test::mark (0x";
|
||||
std::cout << std::hex << reinterpret_cast<u64>(ptr) << std::dec << ") {\n";
|
||||
|
||||
bfs_queue->push_back(static_cast<ghost_obj*>(ptr)->test_string);
|
||||
|
||||
std::cout << " mark 0x" << std::hex;
|
||||
std::cout << reinterpret_cast<u64>(ptr) << std::dec << "->test_string;\n";
|
||||
std::cout << "}\n";
|
||||
|
@ -86,8 +90,10 @@ var set_new_ghost(var* args, usize size, gc* ngc) {
|
|||
return nil;
|
||||
}
|
||||
f64 num = args[1].num();
|
||||
|
||||
reinterpret_cast<ghost_obj*>(res.ghost().pointer)->number = static_cast<u32>(num);
|
||||
std::cout << "set_new_ghost: successfully set ghost.number = " << num << "\n";
|
||||
|
||||
reinterpret_cast<ghost_obj*>(res.ghost().pointer)->test_string = ngc->newstr("just for test");
|
||||
std::cout << "set_new_ghost: successfully set ghost.test_string = just for test\n";
|
||||
return nil;
|
||||
|
|
|
@ -35,8 +35,7 @@ private:
|
|||
std::string format_location(const span& location) {
|
||||
std::stringstream ss;
|
||||
ss << " -> ";
|
||||
ss << location.file << ":";
|
||||
ss << location.begin_line << ":" << location.begin_column + 1;
|
||||
location.dump_begin(ss);
|
||||
ss << "\n";
|
||||
return ss.str();
|
||||
}
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
|
||||
namespace nasal {
|
||||
|
||||
enum class expr_type: u32 {
|
||||
enum class expr_type {
|
||||
ast_null = 0, // null node
|
||||
ast_use, // use statement
|
||||
ast_block, // code block
|
||||
|
@ -65,13 +65,13 @@ public:
|
|||
expr(const span& location, expr_type node_type):
|
||||
nd_loc(location), nd_type(node_type) {}
|
||||
virtual ~expr() = default;
|
||||
void set_begin(u32 line, u32 column) {
|
||||
void set_begin(u64 line, u64 column) {
|
||||
nd_loc.begin_line = line;
|
||||
nd_loc.begin_column = column;
|
||||
}
|
||||
const span& get_location() const {return nd_loc;}
|
||||
const u32 get_line() const {return nd_loc.begin_line;}
|
||||
expr_type get_type() const {return nd_type;}
|
||||
const auto& get_location() const { return nd_loc; }
|
||||
const auto get_line() const { return nd_loc.begin_line; }
|
||||
auto get_type() const { return nd_type; }
|
||||
void update_location(const span& location) {
|
||||
nd_loc.end_line = location.end_line;
|
||||
nd_loc.end_column = location.end_column;
|
||||
|
|
|
@ -260,7 +260,7 @@ void dbg::run(
|
|||
std::vector<u32> code;
|
||||
std::vector<u16> code_file_index;
|
||||
std::vector<u32> code_line;
|
||||
for(auto& i : gen.codes()) {
|
||||
for(const auto& i : gen.codes()) {
|
||||
code.push_back(i.op);
|
||||
code_file_index.push_back(i.fidx);
|
||||
code_line.push_back(i.line);
|
||||
|
|
|
@ -127,15 +127,15 @@ void error::err(
|
|||
|
||||
++cnt;
|
||||
|
||||
std::cerr
|
||||
<< red << stage << ": " << white << info << reset << "\n" << cyan << " --> "
|
||||
<< red << loc.file << ":" << loc.begin_line << ":" << loc.begin_column+1
|
||||
<< reset << "\n";
|
||||
std::cerr << red << stage << ": " << white << info << reset << "\n";
|
||||
std::cerr << cyan << " --> " << red;
|
||||
loc.dump_begin(std::cerr);
|
||||
std::cerr << reset << "\n";
|
||||
|
||||
const usize maxlen = std::to_string(loc.end_line).length();
|
||||
const std::string iden = identation(maxlen);
|
||||
|
||||
for(u32 line = loc.begin_line; line<=loc.end_line; ++line) {
|
||||
for(u64 line = loc.begin_line; line<=loc.end_line; ++line) {
|
||||
// skip line 0
|
||||
if (!line) {
|
||||
continue;
|
||||
|
@ -164,25 +164,25 @@ void error::err(
|
|||
// output underline
|
||||
std::cerr << cyan << iden << " | " << reset;
|
||||
if (loc.begin_line==loc.end_line) {
|
||||
for(u32 i = 0; i<loc.begin_column; ++i) {
|
||||
for(u64 i = 0; i<loc.begin_column; ++i) {
|
||||
std::cerr << char(" \t"[code[i]=='\t']);
|
||||
}
|
||||
for(u32 i = loc.begin_column; i<loc.end_column; ++i) {
|
||||
for(u64 i = loc.begin_column; i<loc.end_column; ++i) {
|
||||
std::cerr << red << (code[i]=='\t'? "^^^^":"^") << reset;
|
||||
}
|
||||
} else if (line==loc.begin_line) {
|
||||
for(u32 i = 0; i<loc.begin_column; ++i) {
|
||||
for(u64 i = 0; i<loc.begin_column; ++i) {
|
||||
std::cerr << char(" \t"[code[i]=='\t']);
|
||||
}
|
||||
for(u32 i = loc.begin_column; i<code.size(); ++i) {
|
||||
for(u64 i = loc.begin_column; i<code.size(); ++i) {
|
||||
std::cerr << red << (code[i]=='\t'? "^^^^":"^") << reset;
|
||||
}
|
||||
} else if (loc.begin_line<line && line<loc.end_line) {
|
||||
for(u32 i = 0; i<code.size(); ++i) {
|
||||
for(u64 i = 0; i<code.size(); ++i) {
|
||||
std::cerr << red << (code[i]=='\t'? "^^^^":"^");
|
||||
}
|
||||
} else {
|
||||
for(u32 i = 0; i<loc.end_column; ++i) {
|
||||
for(u64 i = 0; i<loc.end_column; ++i) {
|
||||
std::cerr << red << (code[i]=='\t'? "^^^^":"^");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,11 +11,15 @@
|
|||
namespace nasal {
|
||||
|
||||
struct span {
|
||||
u32 begin_line;
|
||||
u32 begin_column;
|
||||
u32 end_line;
|
||||
u32 end_column;
|
||||
u64 begin_line;
|
||||
u64 begin_column;
|
||||
u64 end_line;
|
||||
u64 end_column;
|
||||
std::string file;
|
||||
|
||||
void dump_begin(std::ostream& out) const {
|
||||
out << file << ":" << begin_line << ":" << begin_column + 1;
|
||||
}
|
||||
};
|
||||
|
||||
std::ostream& back_white(std::ostream&);
|
||||
|
@ -46,7 +50,7 @@ private:
|
|||
std::string identation(usize len) {
|
||||
return std::string(len, ' ');
|
||||
}
|
||||
std::string leftpad(u32 num, usize len) {
|
||||
std::string leftpad(u64 num, usize len) {
|
||||
auto tmp = std::to_string(num);
|
||||
while(tmp.length()<len) {
|
||||
tmp = " "+tmp;
|
||||
|
@ -65,7 +69,7 @@ public:
|
|||
std::exit(1);
|
||||
}
|
||||
}
|
||||
u32 geterr() const {return cnt;}
|
||||
auto geterr() const { return cnt; }
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -96,7 +96,7 @@ void lexer::open(const std::string& file) {
|
|||
}
|
||||
|
||||
tok lexer::get_type(const std::string& str) {
|
||||
return typetbl.count(str)? typetbl.at(str):tok::null;
|
||||
return token_mapper.count(str)? token_mapper.at(str):tok::null;
|
||||
}
|
||||
|
||||
std::string lexer::utf8_gen() {
|
||||
|
@ -138,8 +138,8 @@ std::string lexer::utf8_gen() {
|
|||
}
|
||||
|
||||
token lexer::id_gen() {
|
||||
u32 begin_line = line;
|
||||
u32 begin_column = column;
|
||||
u64 begin_line = line;
|
||||
u64 begin_column = column;
|
||||
std::string str = "";
|
||||
while(ptr<res.size() && (is_id(res[ptr]) || is_dec(res[ptr]))) {
|
||||
if (res[ptr]<0) { // utf-8
|
||||
|
@ -157,8 +157,8 @@ token lexer::id_gen() {
|
|||
}
|
||||
|
||||
token lexer::num_gen() {
|
||||
u32 begin_line = line;
|
||||
u32 begin_column = column;
|
||||
u64 begin_line = line;
|
||||
u64 begin_column = column;
|
||||
// generate hex number
|
||||
if (ptr+1<res.size() && res[ptr]=='0' && res[ptr+1]=='x') {
|
||||
std::string str = "0x";
|
||||
|
@ -239,8 +239,8 @@ token lexer::num_gen() {
|
|||
}
|
||||
|
||||
token lexer::str_gen() {
|
||||
u32 begin_line = line;
|
||||
u32 begin_column = column;
|
||||
u64 begin_line = line;
|
||||
u64 begin_column = column;
|
||||
std::string str = "";
|
||||
const char begin = res[ptr];
|
||||
++column;
|
||||
|
@ -298,8 +298,8 @@ token lexer::str_gen() {
|
|||
}
|
||||
|
||||
token lexer::single_opr() {
|
||||
u32 begin_line = line;
|
||||
u32 begin_column = column;
|
||||
u64 begin_line = line;
|
||||
u64 begin_column = column;
|
||||
std::string str(1, res[ptr]);
|
||||
++column;
|
||||
tok type = get_type(str);
|
||||
|
@ -314,8 +314,8 @@ token lexer::single_opr() {
|
|||
}
|
||||
|
||||
token lexer::dots() {
|
||||
u32 begin_line = line;
|
||||
u32 begin_column = column;
|
||||
u64 begin_line = line;
|
||||
u64 begin_column = column;
|
||||
std::string str = ".";
|
||||
if (ptr+2<res.size() && res[ptr+1]=='.' && res[ptr+2]=='.') {
|
||||
str += "..";
|
||||
|
@ -326,8 +326,8 @@ token lexer::dots() {
|
|||
}
|
||||
|
||||
token lexer::calc_opr() {
|
||||
u32 begin_line = line;
|
||||
u32 begin_column = column;
|
||||
u64 begin_line = line;
|
||||
u64 begin_column = column;
|
||||
// get calculation operator
|
||||
std::string str(1, res[ptr++]);
|
||||
if (ptr<res.size() && res[ptr]=='=') {
|
||||
|
|
|
@ -88,8 +88,8 @@ struct token {
|
|||
|
||||
class lexer {
|
||||
private:
|
||||
u32 line;
|
||||
u32 column;
|
||||
u64 line;
|
||||
u64 column;
|
||||
usize ptr;
|
||||
std::string filename;
|
||||
std::string res;
|
||||
|
@ -98,7 +98,7 @@ private:
|
|||
u64 invalid_char;
|
||||
std::vector<token> toks;
|
||||
|
||||
const std::unordered_map<std::string, tok> typetbl {
|
||||
const std::unordered_map<std::string, tok> token_mapper = {
|
||||
{"use" ,tok::use },
|
||||
{"true" ,tok::tktrue },
|
||||
{"false" ,tok::tkfalse },
|
||||
|
|
|
@ -101,7 +101,7 @@ struct opcode {
|
|||
u8 op; // opcode
|
||||
u16 fidx; // source code file index
|
||||
u32 num; // immediate num
|
||||
u32 line; // location line of source code
|
||||
u64 line; // location line of source code
|
||||
opcode() = default;
|
||||
opcode(const opcode&) = default;
|
||||
opcode& operator=(const opcode&) = default;
|
||||
|
|
|
@ -105,7 +105,7 @@ bool parse::check_comma(const tok* panic_set) {
|
|||
}
|
||||
|
||||
bool parse::check_tuple() {
|
||||
u32 check_ptr=ptr, curve=1, bracket=0, brace=0;
|
||||
u64 check_ptr = ptr, curve = 1, bracket = 0, brace = 0;
|
||||
while(toks[++check_ptr].type!=tok::eof && curve) {
|
||||
switch(toks[check_ptr].type) {
|
||||
case tok::lcurve: ++curve; break;
|
||||
|
@ -157,7 +157,7 @@ bool parse::check_in_curve_multi_definition() {
|
|||
|
||||
bool parse::check_special_call() {
|
||||
// special call means like this: function_name(a:1,b:2,c:3);
|
||||
u32 check_ptr = ptr, curve = 1, bracket = 0, brace = 0;
|
||||
u64 check_ptr = ptr, curve = 1, bracket = 0, brace = 0;
|
||||
while(toks[++check_ptr].type!=tok::eof && curve) {
|
||||
switch(toks[check_ptr].type) {
|
||||
case tok::lcurve: ++curve; break;
|
||||
|
|
|
@ -15,9 +15,9 @@ class parse {
|
|||
#define prevspan (ptr!=0? toks[ptr-1].loc:toks[ptr].loc)
|
||||
|
||||
private:
|
||||
u32 ptr;
|
||||
u32 in_func; // count function block
|
||||
u32 in_loop; // count loop block
|
||||
u64 ptr;
|
||||
u64 in_func; // count function block
|
||||
u64 in_loop; // count loop block
|
||||
const token* toks;
|
||||
code_block* root;
|
||||
error err;
|
||||
|
|
|
@ -451,7 +451,7 @@ void vm::run(
|
|||
&&mcallv, &&mcallh, &&ret
|
||||
};
|
||||
std::vector<const void*> code;
|
||||
for(auto& i : gen.codes()) {
|
||||
for(const auto& i : gen.codes()) {
|
||||
code.push_back(oprs[i.op]);
|
||||
imm.push_back(i.num);
|
||||
}
|
||||
|
@ -506,7 +506,7 @@ void vm::run(
|
|||
&vm::o_ret
|
||||
};
|
||||
std::vector<nafunc> code;
|
||||
for(auto& i : gen.codes()) {
|
||||
for(const auto& i : gen.codes()) {
|
||||
code.push_back(oprs[i.op]);
|
||||
imm.push_back(i.num);
|
||||
}
|
||||
|
|
|
@ -339,6 +339,7 @@ var builtin_left(context* ctx, gc* ngc) {
|
|||
auto local = ctx->localr;
|
||||
var str = local[1];
|
||||
var len = local[2];
|
||||
|
||||
if (!str.is_str()) {
|
||||
return nas_err("left", "\"string\" must be string");
|
||||
}
|
||||
|
@ -355,20 +356,23 @@ var builtin_right(context* ctx, gc* ngc) {
|
|||
auto local = ctx->localr;
|
||||
var str = local[1];
|
||||
var len = local[2];
|
||||
|
||||
if (!str.is_str()) {
|
||||
return nas_err("right", "\"string\" must be string");
|
||||
}
|
||||
if (!len.is_num()) {
|
||||
return nas_err("right", "\"length\" must be number");
|
||||
}
|
||||
|
||||
i32 length = static_cast<i32>(len.num());
|
||||
i32 srclen = str.str().length();
|
||||
i32 srclen = static_cast<i32>(str.str().length());
|
||||
if (length>srclen) {
|
||||
length = srclen;
|
||||
}
|
||||
if (length<0) {
|
||||
length = 0;
|
||||
}
|
||||
|
||||
return ngc->newstr(str.str().substr(srclen-length, srclen));
|
||||
}
|
||||
|
||||
|
@ -566,12 +570,12 @@ public:
|
|||
}
|
||||
|
||||
f64 elapsed_milliseconds() {
|
||||
auto duration = std::chrono::high_resolution_clock::now() - stamp;
|
||||
const auto duration = std::chrono::high_resolution_clock::now() - stamp;
|
||||
return std::chrono::duration_cast<std::chrono::milliseconds>(duration).count();
|
||||
}
|
||||
|
||||
f64 elapsed_microseconds() {
|
||||
auto duration = std::chrono::high_resolution_clock::now() - stamp;
|
||||
const auto duration = std::chrono::high_resolution_clock::now() - stamp;
|
||||
return std::chrono::duration_cast<std::chrono::microseconds>(duration).count();
|
||||
}
|
||||
};
|
||||
|
|
|
@ -66,10 +66,12 @@ var builtin_values(context*, gc*);
|
|||
var builtin_sleep(context*, gc*);
|
||||
var builtin_platform(context*, gc*);
|
||||
var builtin_arch(context*, gc*);
|
||||
|
||||
// md5 related functions
|
||||
std::string tohex(u32);
|
||||
std::string md5(const std::string&);
|
||||
var builtin_md5(context*, gc*);
|
||||
|
||||
var builtin_maketimestamp(context*, gc*);
|
||||
var builtin_time_stamp(context*, gc*);
|
||||
var builtin_elapsed_millisecond(context*, gc*);
|
||||
|
|
|
@ -4,8 +4,6 @@ import os
|
|||
import platform
|
||||
import shutil
|
||||
|
||||
nasal_version = "11.2"
|
||||
|
||||
build_directory = pathlib.Path("build")
|
||||
if not os.path.exists(build_directory):
|
||||
print("pack binaries failed: build directory not found")
|
||||
|
|
Loading…
Reference in New Issue