🐛 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:
parent
94f7c941f6
commit
c858afbb76
|
@ -74,6 +74,8 @@ Use g++/clang++ on `Linux/macOS/Unix` platform (we suggest `clang`).
|
|||
|
||||
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
|
||||
|
||||
You could create project in `Visual Studio` by this way: [__Click__](./doc/vs.md).
|
||||
|
|
|
@ -65,6 +65,8 @@ __注意__: 如果你想直接下载发行版提供的zip/tar.gz压缩包来构
|
|||
|
||||
`Windows` 平台(`MinGW-w64`):
|
||||
|
||||
一定要确保您的 MinGW thread model 是 `posix thread model`, 否则可能存在没有 thread 库的问题。
|
||||
|
||||
> mingw32-make nasal.exe
|
||||
|
||||
你也可以在`Visual Studio`中用这种方式来创建项目:[__点击跳转__](../doc/vs.md)。
|
||||
|
|
17
main.cpp
17
main.cpp
|
@ -72,6 +72,7 @@ void err() {
|
|||
|
||||
void execute(const string& file,const std::vector<string>& argv,const u32 cmd) {
|
||||
using clk=std::chrono::high_resolution_clock;
|
||||
const auto den=clk::duration::period::den;
|
||||
|
||||
error err;
|
||||
lexer lex(err);
|
||||
|
@ -102,16 +103,16 @@ void execute(const string& file,const std::vector<string>& argv,const u32 cmd) {
|
|||
}
|
||||
|
||||
// run
|
||||
auto start=clk::now();
|
||||
if (cmd&VM_DEBUG) {
|
||||
dbg(err).run(gen,ld,argv);
|
||||
} else if (cmd&VM_TIME) {
|
||||
auto start=clk::now();
|
||||
ctx.run(gen,ld,argv,cmd&VM_DETAIL);
|
||||
auto end=clk::now();
|
||||
std::clog<<"process exited after "<<(end-start).count()*1.0/clk::duration::period::den<<"s.\n\n";
|
||||
} else if (cmd&VM_EXEC) {
|
||||
} else if (cmd&VM_TIME || cmd&VM_EXEC) {
|
||||
ctx.run(gen,ld,argv,cmd&VM_DETAIL);
|
||||
}
|
||||
if (cmd&VM_TIME) {
|
||||
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[]) {
|
||||
|
@ -135,7 +136,7 @@ i32 main(i32 argc,const char* argv[]) {
|
|||
}
|
||||
|
||||
// execute with arguments
|
||||
std::unordered_map<string,u32> cmdlst={
|
||||
const std::unordered_map<string,u32> cmdlst={
|
||||
{"--ast",VM_AST},{"-a",VM_AST},
|
||||
{"--code",VM_CODE},{"-c",VM_CODE},
|
||||
{"--exec",VM_EXEC},{"-e",VM_EXEC},
|
||||
|
@ -148,7 +149,7 @@ i32 main(i32 argc,const char* argv[]) {
|
|||
std::vector<string> vm_argv;
|
||||
for(i32 i=1;i<argc;++i) {
|
||||
if (cmdlst.count(argv[i])) {
|
||||
cmd|=cmdlst[argv[i]];
|
||||
cmd|=cmdlst.at(argv[i]);
|
||||
} else if (!filename.length()) {
|
||||
filename=argv[i];
|
||||
} else {
|
||||
|
|
|
@ -777,7 +777,13 @@ var builtin_sleep(var* local,gc& ngc) {
|
|||
if (val.type!=vm_num) {
|
||||
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)));
|
||||
#endif
|
||||
return nil;
|
||||
}
|
||||
|
||||
|
|
|
@ -91,7 +91,7 @@ private:
|
|||
string res;
|
||||
error& err;
|
||||
std::vector<token> toks;
|
||||
std::unordered_map<string,tok> typetbl {
|
||||
const std::unordered_map<string,tok> typetbl {
|
||||
{"true" ,tok::tktrue },
|
||||
{"false" ,tok::tkfalse },
|
||||
{"for" ,tok::rfor },
|
||||
|
|
|
@ -76,7 +76,7 @@ enum op_code_type:u8 {
|
|||
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_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_callvi, // call vec[immediate] (used in multi-assign/multi-define)
|
||||
op_callh, // call hash.label
|
||||
|
@ -147,7 +147,11 @@ const f64* codestream::nums=nullptr;
|
|||
const string* codestream::strs=nullptr;
|
||||
const string* codestream::files=nullptr;
|
||||
|
||||
void codestream::set(const f64* numbuff,const string* strbuff,const string* filelist=nullptr) {
|
||||
void codestream::set(
|
||||
const f64* numbuff,
|
||||
const string* strbuff,
|
||||
const string* filelist=nullptr
|
||||
) {
|
||||
nums=numbuff;
|
||||
strs=strbuff;
|
||||
files=filelist;
|
||||
|
@ -168,39 +172,49 @@ void codestream::dump(std::ostream& out) const {
|
|||
<<setw(2)<<setfill('0')<<(num&0xff)<<" "
|
||||
<<opname[op]<<" "<<dec;
|
||||
switch(op) {
|
||||
case op_addeq: case op_subeq: case op_muleq: case op_diveq:
|
||||
case op_lnkeq: case op_meq: case op_btandeq: case op_btoreq:
|
||||
case op_addeq: case op_subeq:
|
||||
case op_muleq: case op_diveq:
|
||||
case op_lnkeq: case op_meq:
|
||||
case op_btandeq: case op_btoreq:
|
||||
case op_btxoreq:
|
||||
out<<hex<<"0x"<<num<<dec<<" sp-"<<num;break;
|
||||
case op_addeqc:case op_subeqc: case op_muleqc:case op_diveqc:
|
||||
case op_addeqc: case op_subeqc:
|
||||
case op_muleqc:case op_diveqc:
|
||||
out<<hex<<"0x"<<num<<dec<<" ("<<nums[num]<<")";break;
|
||||
case op_lnkeqc:
|
||||
out<<hex<<"0x"<<num<<dec<<" ("<<rawstr(strs[num],16)<<")";break;
|
||||
case op_addecp:case op_subecp:case op_mulecp:case op_divecp:
|
||||
case op_addecp: case op_subecp:
|
||||
case op_mulecp: case op_divecp:
|
||||
out<<hex<<"0x"<<num<<dec<<" ("<<nums[num]<<") sp-1";break;
|
||||
case op_lnkecp:
|
||||
out<<hex<<"0x"<<num<<dec<<" ("<<rawstr(strs[num],16)<<") sp-1";break;
|
||||
case op_addc: case op_subc: case op_mulc: case op_divc:
|
||||
case op_lessc: case op_leqc: case op_grtc: case op_geqc:
|
||||
case op_addc: case op_subc:
|
||||
case op_mulc: case op_divc:
|
||||
case op_lessc: case op_leqc:
|
||||
case op_grtc: case op_geqc:
|
||||
case op_pnum:
|
||||
out<<hex<<"0x"<<num<<dec<<" ("<<nums[num]<<")";break;
|
||||
case op_callvi:case op_newv: case op_callfv:
|
||||
case op_intg: case op_intl:
|
||||
case op_findex:case op_feach:
|
||||
case op_newf: case op_jmp: case op_jt: case op_jf:
|
||||
case op_callg: case op_mcallg: case op_loadg:
|
||||
case op_calll: case op_mcalll: case op_loadl:
|
||||
case op_callvi: case op_newv:
|
||||
case op_callfv: case op_intg:
|
||||
case op_intl: case op_findex:
|
||||
case op_feach: case op_newf:
|
||||
case op_jmp: case op_jt:
|
||||
case op_jf: case op_callg:
|
||||
case op_mcallg: case op_loadg:
|
||||
case op_calll: case op_mcalll:
|
||||
case op_loadl:
|
||||
out<<hex<<"0x"<<num<<dec;break;
|
||||
case op_callb:
|
||||
out<<hex<<"0x"<<num<<" <"<<builtin[num].name
|
||||
<<"@0x"<<(u64)builtin[num].func<<dec<<">";break;
|
||||
case op_upval: case op_mupval: case op_loadu:
|
||||
case op_upval: case op_mupval:
|
||||
case op_loadu:
|
||||
out<<hex<<"0x"<<((num>>16)&0xffff)
|
||||
<<"[0x"<<(num&0xffff)<<"]"<<dec;break;
|
||||
case op_happ: case op_pstr:
|
||||
case op_lnkc:
|
||||
case op_callh: case op_mcallh:
|
||||
case op_para: case op_deft: case op_dyn:
|
||||
case op_happ: case op_pstr:
|
||||
case op_lnkc: case op_callh:
|
||||
case op_mcallh: case op_para:
|
||||
case op_deft: case op_dyn:
|
||||
out<<hex<<"0x"<<num<<dec<<" ("<<rawstr(strs[num],16)<<")";break;
|
||||
default:
|
||||
if (files) {
|
||||
|
|
Loading…
Reference in New Issue