🐛 fix compilation error

in windows mingw-w64 win32 thread model,
but we do not suggest you to use this,
please use posix thread model
This commit is contained in:
ValKmjolnir 2023-04-23 00:02:39 +08:00
parent 94f7c941f6
commit c858afbb76
6 changed files with 406 additions and 381 deletions

View File

@ -74,6 +74,8 @@ Use g++/clang++ on `Linux/macOS/Unix` platform (we suggest `clang`).
On `Windows (MinGW-w64)`: On `Windows (MinGW-w64)`:
Make sure your MinGW thread model is `posix thread model`, otherwise it may not have the thread library.
> mingw32-make nasal.exe > mingw32-make nasal.exe
You could create project in `Visual Studio` by this way: [__Click__](./doc/vs.md). You could create project in `Visual Studio` by this way: [__Click__](./doc/vs.md).

View File

@ -65,6 +65,8 @@ __注意__: 如果你想直接下载发行版提供的zip/tar.gz压缩包来构
`Windows` 平台(`MinGW-w64`): `Windows` 平台(`MinGW-w64`):
一定要确保您的 MinGW thread model 是 `posix thread model`, 否则可能存在没有 thread 库的问题。
> mingw32-make nasal.exe > mingw32-make nasal.exe
你也可以在`Visual Studio`中用这种方式来创建项目:[__点击跳转__](../doc/vs.md)。 你也可以在`Visual Studio`中用这种方式来创建项目:[__点击跳转__](../doc/vs.md)。

325
main.cpp
View File

@ -1,163 +1,164 @@
#include "nasal.h" #include "nasal.h"
#include "nasal_err.h" #include "nasal_err.h"
#include "nasal_lexer.h" #include "nasal_lexer.h"
#include "nasal_ast.h" #include "nasal_ast.h"
#include "nasal_parse.h" #include "nasal_parse.h"
#include "nasal_import.h" #include "nasal_import.h"
#include "nasal_opt.h" #include "nasal_opt.h"
#include "nasal_gc.h" #include "nasal_gc.h"
#include "nasal_builtin.h" #include "nasal_builtin.h"
#include "nasal_codegen.h" #include "nasal_codegen.h"
#include "nasal_vm.h" #include "nasal_vm.h"
#include "nasal_dbg.h" #include "nasal_dbg.h"
#include <unordered_map> #include <unordered_map>
const u32 VM_AST =0x01; const u32 VM_AST =0x01;
const u32 VM_CODE =0x02; const u32 VM_CODE =0x02;
const u32 VM_TIME =0x04; const u32 VM_TIME =0x04;
const u32 VM_EXEC =0x08; const u32 VM_EXEC =0x08;
const u32 VM_DETAIL=0x10; const u32 VM_DETAIL=0x10;
const u32 VM_DEBUG =0x20; const u32 VM_DEBUG =0x20;
std::ostream& help(std::ostream& out) { std::ostream& help(std::ostream& out) {
out out
<<" ,--#-,\n" <<" ,--#-,\n"
<<"<3 / \\____\\ <3\n" <<"<3 / \\____\\ <3\n"
<<" |_|__A_|\n" <<" |_|__A_|\n"
#ifdef _WIN32 #ifdef _WIN32
<<"use command <chcp 65001> to use unicode.\n" <<"use command <chcp 65001> to use unicode.\n"
#endif #endif
<<"\nnasal <option>\n" <<"\nnasal <option>\n"
<<"option:\n" <<"option:\n"
<<" -h, --help | get help.\n" <<" -h, --help | get help.\n"
<<"\nnasal [option] <file> [argv]\n" <<"\nnasal [option] <file> [argv]\n"
<<"option:\n" <<"option:\n"
<<" -a, --ast | view abstract syntax tree.\n" <<" -a, --ast | view abstract syntax tree.\n"
<<" -c, --code | view bytecode.\n" <<" -c, --code | view bytecode.\n"
<<" -e, --exec | execute.\n" <<" -e, --exec | execute.\n"
<<" -t, --time | show execute time.\n" <<" -t, --time | show execute time.\n"
<<" -d, --detail | get detail info.\n" <<" -d, --detail | get detail info.\n"
<<" -dbg, --debug | debug mode.\n" <<" -dbg, --debug | debug mode.\n"
<<"file:\n" <<"file:\n"
<<" <filename> | execute file.\n" <<" <filename> | execute file.\n"
<<"argv:\n" <<"argv:\n"
<<" <args> | cmd arguments used in program.\n"; <<" <args> | cmd arguments used in program.\n";
return out; return out;
} }
std::ostream& logo(std::ostream& out) { std::ostream& logo(std::ostream& out) {
out out
<<" __ _\n" <<" __ _\n"
<<" /\\ \\ \\__ _ ___ __ _| |\n" <<" /\\ \\ \\__ _ ___ __ _| |\n"
<<" / \\/ / _` / __|/ _` | |\n" <<" / \\/ / _` / __|/ _` | |\n"
<<" / /\\ / (_| \\__ \\ (_| | |\n" <<" / /\\ / (_| \\__ \\ (_| | |\n"
<<" \\_\\ \\/ \\__,_|___/\\__,_|_|\n" <<" \\_\\ \\/ \\__,_|___/\\__,_|_|\n"
<<"ver : "<<__nasver<<" ("<<__DATE__<<" "<<__TIME__<<")\n" <<"ver : "<<__nasver<<" ("<<__DATE__<<" "<<__TIME__<<")\n"
<<"std : c++ "<<__cplusplus<<"\n" <<"std : c++ "<<__cplusplus<<"\n"
<<"repo : https://github.com/ValKmjolnir/Nasal-Interpreter\n" <<"repo : https://github.com/ValKmjolnir/Nasal-Interpreter\n"
<<"repo : https://gitee.com/valkmjolnir/Nasal-Interpreter\n" <<"repo : https://gitee.com/valkmjolnir/Nasal-Interpreter\n"
<<"wiki : https://wiki.flightgear.org/Nasal_scripting_language\n" <<"wiki : https://wiki.flightgear.org/Nasal_scripting_language\n"
<<"input <nasal -h> to get help .\n"; <<"input <nasal -h> to get help .\n";
return out; return out;
} }
[[noreturn]] [[noreturn]]
void err() { void err() {
std::cerr std::cerr
<<"invalid argument(s).\n" <<"invalid argument(s).\n"
<<"use <nasal -h> to get help.\n"; <<"use <nasal -h> to get help.\n";
std::exit(1); std::exit(1);
} }
void execute(const string& file,const std::vector<string>& argv,const u32 cmd) { void execute(const string& file,const std::vector<string>& argv,const u32 cmd) {
using clk=std::chrono::high_resolution_clock; using clk=std::chrono::high_resolution_clock;
const auto den=clk::duration::period::den;
error err;
lexer lex(err); error err;
parse parse(err); lexer lex(err);
linker ld(err); parse parse(err);
codegen gen(err); linker ld(err);
vm ctx; codegen gen(err);
vm ctx;
// lexer scans file to get tokens
lex.scan(file).chkerr(); // lexer scans file to get tokens
lex.scan(file).chkerr();
// parser gets lexer's token list to compile
parse.compile(lex).chkerr(); // parser gets lexer's token list to compile
parse.compile(lex).chkerr();
// linker gets parser's ast and load import files to this ast
ld.link(parse,file,cmd&VM_DETAIL).chkerr(); // linker gets parser's ast and load import files to this ast
ld.link(parse,file,cmd&VM_DETAIL).chkerr();
// optimizer does simple optimization on ast
optimize(parse.tree()); // optimizer does simple optimization on ast
if (cmd&VM_AST) { optimize(parse.tree());
parse.tree().dump(); if (cmd&VM_AST) {
} parse.tree().dump();
}
// code generator gets parser's ast and linker's import file list to generate code
gen.compile(parse,ld).chkerr(); // code generator gets parser's ast and linker's import file list to generate code
if (cmd&VM_CODE) { gen.compile(parse,ld).chkerr();
gen.print(); if (cmd&VM_CODE) {
} gen.print();
}
// run
if (cmd&VM_DEBUG) { // run
dbg(err).run(gen,ld,argv); auto start=clk::now();
} else if (cmd&VM_TIME) { if (cmd&VM_DEBUG) {
auto start=clk::now(); dbg(err).run(gen,ld,argv);
ctx.run(gen,ld,argv,cmd&VM_DETAIL); } else if (cmd&VM_TIME || cmd&VM_EXEC) {
auto end=clk::now(); ctx.run(gen,ld,argv,cmd&VM_DETAIL);
std::clog<<"process exited after "<<(end-start).count()*1.0/clk::duration::period::den<<"s.\n\n"; }
} else if (cmd&VM_EXEC) { if (cmd&VM_TIME) {
ctx.run(gen,ld,argv,cmd&VM_DETAIL); f64 tm=(clk::now()-start).count()*1.0/den;
} std::clog<<"process exited after "<<tm<<"s.\n\n";
} }
}
i32 main(i32 argc,const char* argv[]) {
// output version info i32 main(i32 argc,const char* argv[]) {
if (argc<=1) { // output version info
std::clog<<logo; if (argc<=1) {
return 0; std::clog<<logo;
} return 0;
}
// run directly or show help
if (argc==2) { // run directly or show help
string s(argv[1]); if (argc==2) {
if (s=="-h" || s=="--help") { string s(argv[1]);
std::clog<<help; if (s=="-h" || s=="--help") {
} else if (s[0]!='-') { std::clog<<help;
execute(s,{},VM_EXEC); } else if (s[0]!='-') {
} else { execute(s,{},VM_EXEC);
err(); } else {
} err();
return 0; }
} return 0;
}
// execute with arguments
std::unordered_map<string,u32> cmdlst={ // execute with arguments
{"--ast",VM_AST},{"-a",VM_AST}, const std::unordered_map<string,u32> cmdlst={
{"--code",VM_CODE},{"-c",VM_CODE}, {"--ast",VM_AST},{"-a",VM_AST},
{"--exec",VM_EXEC},{"-e",VM_EXEC}, {"--code",VM_CODE},{"-c",VM_CODE},
{"--time",VM_TIME|VM_EXEC},{"-t",VM_TIME|VM_EXEC}, {"--exec",VM_EXEC},{"-e",VM_EXEC},
{"--detail",VM_DETAIL|VM_EXEC},{"-d",VM_DETAIL|VM_EXEC}, {"--time",VM_TIME|VM_EXEC},{"-t",VM_TIME|VM_EXEC},
{"--debug",VM_DEBUG},{"-dbg",VM_DEBUG} {"--detail",VM_DETAIL|VM_EXEC},{"-d",VM_DETAIL|VM_EXEC},
}; {"--debug",VM_DEBUG},{"-dbg",VM_DEBUG}
u32 cmd=0; };
string filename=""; u32 cmd=0;
std::vector<string> vm_argv; string filename="";
for(i32 i=1;i<argc;++i) { std::vector<string> vm_argv;
if (cmdlst.count(argv[i])) { for(i32 i=1;i<argc;++i) {
cmd|=cmdlst[argv[i]]; if (cmdlst.count(argv[i])) {
} else if (!filename.length()) { cmd|=cmdlst.at(argv[i]);
filename=argv[i]; } else if (!filename.length()) {
} else { filename=argv[i];
vm_argv.push_back(argv[i]); } else {
} vm_argv.push_back(argv[i]);
} }
if (!filename.length()) { }
err(); if (!filename.length()) {
} err();
execute(filename,vm_argv,cmd?cmd:VM_EXEC); }
return 0; execute(filename,vm_argv,cmd?cmd:VM_EXEC);
return 0;
} }

View File

@ -777,7 +777,13 @@ var builtin_sleep(var* local,gc& ngc) {
if (val.type!=vm_num) { if (val.type!=vm_num) {
return nil; return nil;
} }
#if defined(_WIN32) && !defined(_GLIBCXX_HAS_GTHREADS)
// mingw-w64 win32 thread model has no std::this_thread
// also msvc will use this
Sleep(i64(val.num()*1e3));
#else
std::this_thread::sleep_for(std::chrono::microseconds(i64(val.num()*1e6))); std::this_thread::sleep_for(std::chrono::microseconds(i64(val.num()*1e6)));
#endif
return nil; return nil;
} }

View File

@ -91,7 +91,7 @@ private:
string res; string res;
error& err; error& err;
std::vector<token> toks; std::vector<token> toks;
std::unordered_map<string,tok> typetbl { const std::unordered_map<string,tok> typetbl {
{"true" ,tok::tktrue }, {"true" ,tok::tktrue },
{"false" ,tok::tkfalse }, {"false" ,tok::tkfalse },
{"for" ,tok::rfor }, {"for" ,tok::rfor },

View File

@ -1,219 +1,233 @@
#pragma once #pragma once
#include "nasal.h" #include "nasal.h"
#include "nasal_builtin.h" #include "nasal_builtin.h"
#include <iostream> #include <iostream>
enum op_code_type:u8 { enum op_code_type:u8 {
op_exit, // stop the virtual machine op_exit, // stop the virtual machine
op_intg, // global scope size, set stack top op_intg, // global scope size, set stack top
op_intl, // local scope size op_intl, // local scope size
op_loadg, // load global value op_loadg, // load global value
op_loadl, // load local value op_loadl, // load local value
op_loadu, // load upvalue op_loadu, // load upvalue
op_pnum, // push constant number to the stack op_pnum, // push constant number to the stack
op_pnil, // push constant nil to the stack op_pnil, // push constant nil to the stack
op_pstr, // push constant string to the stack op_pstr, // push constant string to the stack
op_newv, // push new vector with initial values from stack op_newv, // push new vector with initial values from stack
op_newh, // push new hash to the stack op_newh, // push new hash to the stack
op_newf, // push new function to the stack op_newf, // push new function to the stack
op_happ, // hash append op_happ, // hash append
op_para, // normal parameter op_para, // normal parameter
op_deft, // default parameter op_deft, // default parameter
op_dyn, // dynamic parameter op_dyn, // dynamic parameter
op_lnot, // ! logical negation op_lnot, // ! logical negation
op_usub, // - negation op_usub, // - negation
op_bnot, // ~ bitwise not static_cast<i32> op_bnot, // ~ bitwise not static_cast<i32>
op_btor, // | bitwise or op_btor, // | bitwise or
op_btxor, // ^ bitwise xor op_btxor, // ^ bitwise xor
op_btand, // & bitwise and op_btand, // & bitwise and
op_add, // + op_add, // +
op_sub, // - op_sub, // -
op_mul, // * op_mul, // *
op_div, // / op_div, // /
op_lnk, // ~ op_lnk, // ~
op_addc, // + const op_addc, // + const
op_subc, // - const op_subc, // - const
op_mulc, // * const op_mulc, // * const
op_divc, // / const op_divc, // / const
op_lnkc, // ~ const op_lnkc, // ~ const
op_addeq, // += maybe pop stack top op_addeq, // += maybe pop stack top
op_subeq, // -= maybe pop stack top op_subeq, // -= maybe pop stack top
op_muleq, // *= maybe pop stack top op_muleq, // *= maybe pop stack top
op_diveq, // /= maybe pop stack top op_diveq, // /= maybe pop stack top
op_lnkeq, // ~= maybe pop stack top op_lnkeq, // ~= maybe pop stack top
op_btandeq,// &= maybe pop stack top op_btandeq,// &= maybe pop stack top
op_btoreq, // |= maybe pop stack top op_btoreq, // |= maybe pop stack top
op_btxoreq,// ^= maybe pop stack top op_btxoreq,// ^= maybe pop stack top
op_addeqc, // += const don't pop stack top op_addeqc, // += const don't pop stack top
op_subeqc, // -= const don't pop stack top op_subeqc, // -= const don't pop stack top
op_muleqc, // *= const don't pop stack top op_muleqc, // *= const don't pop stack top
op_diveqc, // /= const don't pop stack top op_diveqc, // /= const don't pop stack top
op_lnkeqc, // ~= const don't pop stack top op_lnkeqc, // ~= const don't pop stack top
op_addecp, // += const and pop stack top op_addecp, // += const and pop stack top
op_subecp, // -= const and pop stack top op_subecp, // -= const and pop stack top
op_mulecp, // *= const and pop stack top op_mulecp, // *= const and pop stack top
op_divecp, // /= const and pop stack top op_divecp, // /= const and pop stack top
op_lnkecp, // ~= concat const string and pop stack top op_lnkecp, // ~= concat const string and pop stack top
op_meq, // = maybe pop stack top op_meq, // = maybe pop stack top
op_eq, // == op_eq, // ==
op_neq, // != op_neq, // !=
op_less, // < op_less, // <
op_leq, // <= op_leq, // <=
op_grt, // > op_grt, // >
op_geq, // >= op_geq, // >=
op_lessc, // < const op_lessc, // < const
op_leqc, // <= const op_leqc, // <= const
op_grtc, // > const op_grtc, // > const
op_geqc, // >= const op_geqc, // >= const
op_pop, // pop a value out of stack top op_pop, // pop a value out of stack top
op_jmp, // jump absolute address with no condition op_jmp, // jump absolute address with no condition
op_jt, // used in operator and/or,jmp when condition is true and DO NOT POP op_jt, // used in operator and/or,jmp when condition is true and DO NOT POP
op_jf, // used in conditional/loop,jmp when condition is false and POP STACK op_jf, // used in conditional/loop,jmp when condition is false and POP STACK
op_cnt, // add counter for forindex/foreach op_cnt, // add counter for forindex/foreach
op_findex, // index counter on the top of forindex_stack plus 1 op_findex, // index counter on the top of forindex_stack plus 1
op_feach, // index counter on the top of forindex_stack plus 1 and get the value in vector op_feach, // index counter on the top of forindex_stack plus 1 and get the value in vector
op_callg, // get value in global scope op_callg, // get value in global scope
op_calll, // get value in local scope op_calll, // get value in local scope
op_upval, // get upvalue in closure, high 16 as the index of upval, low 16 as the index of local op_upval, // get value in closure, high 16 as the index of upval, low 16 as the index of local
op_callv, // call vec[index] op_callv, // call vec[index]
op_callvi, // call vec[immediate] (used in multi-assign/multi-define) op_callvi, // call vec[immediate] (used in multi-assign/multi-define)
op_callh, // call hash.label op_callh, // call hash.label
op_callfv, // call function(vector as parameters) op_callfv, // call function(vector as parameters)
op_callfh, // call function(hash as parameters) op_callfh, // call function(hash as parameters)
op_callb, // call builtin-function op_callb, // call builtin-function
op_slcbeg, // begin of slice like: vec[1,2,3:6,0,-1] op_slcbeg, // begin of slice like: vec[1,2,3:6,0,-1]
op_slcend, // end of slice op_slcend, // end of slice
op_slc, // slice like vec[1] op_slc, // slice like vec[1]
op_slc2, // slice like vec[nil:10] op_slc2, // slice like vec[nil:10]
op_mcallg, // get memory space of value in global scope op_mcallg, // get memory space of value in global scope
op_mcalll, // get memory space of value in local scope op_mcalll, // get memory space of value in local scope
op_mupval, // get memory space of value in closure op_mupval, // get memory space of value in closure
op_mcallv, // get memory space of vec[index] op_mcallv, // get memory space of vec[index]
op_mcallh, // get memory space of hash.label op_mcallh, // get memory space of hash.label
op_ret // return op_ret // return
}; };
const char* opname[]={ const char* opname[]={
"exit ","intg ","intl ","loadg ", "exit ","intg ","intl ","loadg ",
"loadl ","loadu ","pnum ","pnil ", "loadl ","loadu ","pnum ","pnil ",
"pstr ","newv ","newh ","newf ", "pstr ","newv ","newh ","newf ",
"happ ","para ","def ","dyn ", "happ ","para ","def ","dyn ",
"lnot ","usub ","bnot ","btor ", "lnot ","usub ","bnot ","btor ",
"btxor ","btand ","add ","sub ", "btxor ","btand ","add ","sub ",
"mult ","div ","lnk ","addc ", "mult ","div ","lnk ","addc ",
"subc ","multc ","divc ","lnkc ", "subc ","multc ","divc ","lnkc ",
"addeq ","subeq ","muleq ","diveq ", "addeq ","subeq ","muleq ","diveq ",
"lnkeq ","bandeq","boreq ","bxoreq", "lnkeq ","bandeq","boreq ","bxoreq",
"addeqc","subeqc","muleqc","diveqc", "addeqc","subeqc","muleqc","diveqc",
"lnkeqc","addecp","subecp","mulecp", "lnkeqc","addecp","subecp","mulecp",
"divecp","lnkecp","meq ","eq ", "divecp","lnkecp","meq ","eq ",
"neq ","less ","leq ","grt ", "neq ","less ","leq ","grt ",
"geq ","lessc ","leqc ","grtc ", "geq ","lessc ","leqc ","grtc ",
"geqc ","pop ","jmp ","jt ", "geqc ","pop ","jmp ","jt ",
"jf ","cnt ","findx ","feach ", "jf ","cnt ","findx ","feach ",
"callg ","calll ","upval ","callv ", "callg ","calll ","upval ","callv ",
"callvi","callh ","callfv","callfh", "callvi","callh ","callfv","callfh",
"callb ","slcbeg","slcend","slc ", "callb ","slcbeg","slcend","slc ",
"slc2 ","mcallg","mcalll","mupval", "slc2 ","mcallg","mcalll","mupval",
"mcallv","mcallh","ret " "mcallv","mcallh","ret "
}; };
struct opcode { struct opcode {
u8 op; // opcode u8 op; // opcode
u16 fidx; // source code file index u16 fidx; // source code file index
u32 num; // immediate num u32 num; // immediate num
u32 line; // location line of source code u32 line; // location line of source code
opcode() = default; opcode() = default;
opcode(const opcode&) = default; opcode(const opcode&) = default;
opcode& operator=(const opcode&) = default; opcode& operator=(const opcode&) = default;
}; };
class codestream { class codestream {
private: private:
opcode code; opcode code;
const u32 index; const u32 index;
static const f64* nums; static const f64* nums;
static const string* strs; static const string* strs;
static const string* files; static const string* files;
public: public:
codestream(const opcode& c,const u32 i):code(c),index(i) {} codestream(const opcode& c,const u32 i):code(c),index(i) {}
static void set(const f64*,const string*,const string*); static void set(const f64*,const string*,const string*);
void dump(std::ostream&) const; void dump(std::ostream&) const;
}; };
const f64* codestream::nums=nullptr; const f64* codestream::nums=nullptr;
const string* codestream::strs=nullptr; const string* codestream::strs=nullptr;
const string* codestream::files=nullptr; const string* codestream::files=nullptr;
void codestream::set(const f64* numbuff,const string* strbuff,const string* filelist=nullptr) { void codestream::set(
nums=numbuff; const f64* numbuff,
strs=strbuff; const string* strbuff,
files=filelist; const string* filelist=nullptr
} ) {
nums=numbuff;
void codestream::dump(std::ostream& out) const { strs=strbuff;
using std::setw; files=filelist;
using std::setfill; }
using std::hex;
using std::dec; void codestream::dump(std::ostream& out) const {
auto op=code.op; using std::setw;
auto num=code.num; using std::setfill;
out<<hex<<"0x" using std::hex;
<<setw(6)<<setfill('0')<<index<<" " using std::dec;
<<setw(2)<<setfill('0')<<(u32)op<<" " auto op=code.op;
<<setw(2)<<setfill('0')<<((num>>16)&0xff)<<" " auto num=code.num;
<<setw(2)<<setfill('0')<<((num>>8)&0xff)<<" " out<<hex<<"0x"
<<setw(2)<<setfill('0')<<(num&0xff)<<" " <<setw(6)<<setfill('0')<<index<<" "
<<opname[op]<<" "<<dec; <<setw(2)<<setfill('0')<<(u32)op<<" "
switch(op) { <<setw(2)<<setfill('0')<<((num>>16)&0xff)<<" "
case op_addeq: case op_subeq: case op_muleq: case op_diveq: <<setw(2)<<setfill('0')<<((num>>8)&0xff)<<" "
case op_lnkeq: case op_meq: case op_btandeq: case op_btoreq: <<setw(2)<<setfill('0')<<(num&0xff)<<" "
case op_btxoreq: <<opname[op]<<" "<<dec;
out<<hex<<"0x"<<num<<dec<<" sp-"<<num;break; switch(op) {
case op_addeqc:case op_subeqc: case op_muleqc:case op_diveqc: case op_addeq: case op_subeq:
out<<hex<<"0x"<<num<<dec<<" ("<<nums[num]<<")";break; case op_muleq: case op_diveq:
case op_lnkeqc: case op_lnkeq: case op_meq:
out<<hex<<"0x"<<num<<dec<<" ("<<rawstr(strs[num],16)<<")";break; case op_btandeq: case op_btoreq:
case op_addecp:case op_subecp:case op_mulecp:case op_divecp: case op_btxoreq:
out<<hex<<"0x"<<num<<dec<<" ("<<nums[num]<<") sp-1";break; out<<hex<<"0x"<<num<<dec<<" sp-"<<num;break;
case op_lnkecp: case op_addeqc: case op_subeqc:
out<<hex<<"0x"<<num<<dec<<" ("<<rawstr(strs[num],16)<<") sp-1";break; case op_muleqc:case op_diveqc:
case op_addc: case op_subc: case op_mulc: case op_divc: out<<hex<<"0x"<<num<<dec<<" ("<<nums[num]<<")";break;
case op_lessc: case op_leqc: case op_grtc: case op_geqc: case op_lnkeqc:
case op_pnum: out<<hex<<"0x"<<num<<dec<<" ("<<rawstr(strs[num],16)<<")";break;
out<<hex<<"0x"<<num<<dec<<" ("<<nums[num]<<")";break; case op_addecp: case op_subecp:
case op_callvi:case op_newv: case op_callfv: case op_mulecp: case op_divecp:
case op_intg: case op_intl: out<<hex<<"0x"<<num<<dec<<" ("<<nums[num]<<") sp-1";break;
case op_findex:case op_feach: case op_lnkecp:
case op_newf: case op_jmp: case op_jt: case op_jf: out<<hex<<"0x"<<num<<dec<<" ("<<rawstr(strs[num],16)<<") sp-1";break;
case op_callg: case op_mcallg: case op_loadg: case op_addc: case op_subc:
case op_calll: case op_mcalll: case op_loadl: case op_mulc: case op_divc:
out<<hex<<"0x"<<num<<dec;break; case op_lessc: case op_leqc:
case op_callb: case op_grtc: case op_geqc:
out<<hex<<"0x"<<num<<" <"<<builtin[num].name case op_pnum:
<<"@0x"<<(u64)builtin[num].func<<dec<<">";break; out<<hex<<"0x"<<num<<dec<<" ("<<nums[num]<<")";break;
case op_upval: case op_mupval: case op_loadu: case op_callvi: case op_newv:
out<<hex<<"0x"<<((num>>16)&0xffff) case op_callfv: case op_intg:
<<"[0x"<<(num&0xffff)<<"]"<<dec;break; case op_intl: case op_findex:
case op_happ: case op_pstr: case op_feach: case op_newf:
case op_lnkc: case op_jmp: case op_jt:
case op_callh: case op_mcallh: case op_jf: case op_callg:
case op_para: case op_deft: case op_dyn: case op_mcallg: case op_loadg:
out<<hex<<"0x"<<num<<dec<<" ("<<rawstr(strs[num],16)<<")";break; case op_calll: case op_mcalll:
default: case op_loadl:
if (files) { out<<hex<<"0x"<<num<<dec;break;
out<<hex<<"0x"<<num<<dec; case op_callb:
} out<<hex<<"0x"<<num<<" <"<<builtin[num].name
break; <<"@0x"<<(u64)builtin[num].func<<dec<<">";break;
} case op_upval: case op_mupval:
if (files) { case op_loadu:
out<<"("<<files[code.fidx]<<":"<<code.line<<")"; out<<hex<<"0x"<<((num>>16)&0xffff)
} <<"[0x"<<(num&0xffff)<<"]"<<dec;break;
} case op_happ: case op_pstr:
case op_lnkc: case op_callh:
std::ostream& operator<<(std::ostream& out,const codestream& ins) { case op_mcallh: case op_para:
ins.dump(out); case op_deft: case op_dyn:
return out; out<<hex<<"0x"<<num<<dec<<" ("<<rawstr(strs[num],16)<<")";break;
default:
if (files) {
out<<hex<<"0x"<<num<<dec;
}
break;
}
if (files) {
out<<"("<<files[code.fidx]<<":"<<code.line<<")";
}
}
std::ostream& operator<<(std::ostream& out,const codestream& ins) {
ins.dump(out);
return out;
} }