diff --git a/nasal_ast.h b/nasal_ast.h index 8e4e828..05e1762 100644 --- a/nasal_ast.h +++ b/nasal_ast.h @@ -145,6 +145,15 @@ const char* ast_name[]={ }; class ast { +public: + ast(const ast&) = delete; + ast& operator=(const ast&) = delete; + + ast(ast&&) = default; + ast& operator=(ast&&) = default; +private: + void print(u32,bool,std::vector&) const; + private: span loc; u32 nd_type; @@ -155,13 +164,8 @@ private: public: ast(const span& s,const u32 t) : loc(s),nd_type(t),nd_num(0),nd_str("") {} - ast(const ast&) = default; - ast(ast&&) = default; - ast& operator=(const ast&) = default; - ast& operator=(ast&&) = default; void dump() const; - void print(u32,bool,std::vector&) const; void clear(); ast& operator[](usize n) {return nd_child[n];} @@ -169,7 +173,6 @@ public: usize size() const {return nd_child.size();} void add(ast&& node) {nd_child.push_back(std::move(node));} - void add(const ast& node) {nd_child.push_back(node);} void set_begin(const u32,const u32); void set_end(const u32,const u32); void set_type(const u32 t) {nd_type=t;} @@ -177,14 +180,15 @@ public: void set_num(const f64 n) {nd_num=n;} u32 line() const {return loc.end_line;} - u32 col() const {return loc.end_column;} u32 type() const {return nd_type;} f64 num() const {return nd_num;} const string& str() const {return nd_str;} const string& file() const {return loc.file;} const span& location() const {return loc;} + const std::vector& child() const {return nd_child;} std::vector& child() {return nd_child;} + void update_span(); void update_span(const span&); }; diff --git a/nasal_codegen.h b/nasal_codegen.h index 371527f..aab6dd0 100644 --- a/nasal_codegen.h +++ b/nasal_codegen.h @@ -41,10 +41,12 @@ private: void regist_str(const string&); void find_symbol(const ast&); void add_sym(const string&); - i32 local_find(const string&); - i32 global_find(const string&); - i32 upvalue_find(const string&); + i32 local_find(const string&); + i32 global_find(const string&); + i32 upvalue_find(const string&); + void gen(u8,u32,u32); + void num_gen(const ast&); void str_gen(const ast&); void bool_gen(const ast&); @@ -78,6 +80,7 @@ private: void calc_gen(const ast&); void block_gen(const ast&); void ret_gen(const ast&); + public: codegen(error& e):fileindex(0),err(e),file(nullptr) {} const error& compile(const parse&,const linker&); diff --git a/nasal_gc.h b/nasal_gc.h index f3bff45..601b4de 100644 --- a/nasal_gc.h +++ b/nasal_gc.h @@ -18,6 +18,7 @@ #include #include #include +#include #include "nasal.h" #include "nasal_err.h" @@ -713,26 +714,31 @@ void gc::clear() { } void gc::info() { + using std::left; + using std::setw; + using std::setfill; const char* name[]={"str ","vec ","hash ","func ","upval","obj ","co "}; - std::clog<<"\ngarbage collector info (gc count|alloc count|memory size)\n"; + std::clog<<"\ngc info (gc count|alloc count|memory size)\n"; - u32 maxlen=0; + usize ident=0; for(u8 i=0;i>16)&0xff)<<" " - <>8)&0xff)<<" " - <>16)&0xff)<<" " + <>8)&0xff)<<" " + <";break; + out<";break; case op_upval: case op_mupval: case op_loadu: - out<>16)&0xffff) - <<"[0x"<<(num&0xffff)<<"]"<>16)&0xffff) + <<"[0x"<<(num&0xffff)<<"]"<