🚀 update makefile to choose different compilers by users & fix some codes for MSVC to compile.
This commit is contained in:
parent
f1f48b4881
commit
577ecd14df
|
@ -36,6 +36,8 @@
|
|||
*.vcxproj
|
||||
*.vcxproj.filters
|
||||
*.vcxproj.user
|
||||
.vs
|
||||
x64
|
||||
|
||||
# misc
|
||||
nasal
|
||||
|
|
22
README.md
22
README.md
|
@ -127,11 +127,11 @@ __PLEASE USE MINGW ON WINDOWS!__
|
|||
|
||||
Use g++ on __`Windows`__(`MinGW-w64`) platform. Download MinGW-w64 [__HERE__](https://www.mingw-w64.org/downloads/). (otherwise don't blame me for not reminding YOU 👿 )
|
||||
|
||||
> g++ -std=c++11 -O3 main.cpp -o nasal.exe -fno-exceptions -static
|
||||
> $(CXX) -std=c++11 -O3 main.cpp -o nasal.exe -fno-exceptions -static
|
||||
|
||||
Or use g++/clang++ on __`linux/macOS/Unix`__ platform.
|
||||
Or use g++/clang++ on __`linux/macOS/Unix`__ platform (we suggest clang).
|
||||
|
||||
> [cpp compiler] -std=c++11 -O3 main.cpp -o nasal -fno-exceptions -ldl
|
||||
> $(CXX) -std=c++11 -O3 main.cpp -o nasal -fno-exceptions -ldl
|
||||
|
||||
Or using makefile,`mingw32-make` is __`Windows(MinGW-w64)`__ platform's `make`:
|
||||
|
||||
|
@ -143,6 +143,22 @@ on __`linux/macOS/Unix`__:
|
|||
|
||||
> make nasal
|
||||
|
||||
You could choose which compiler you want to use by add this after the command:
|
||||
|
||||
> CXX=clang++
|
||||
>
|
||||
> CXX=g++
|
||||
>
|
||||
> CXX=...
|
||||
|
||||
If you think `-O3` isn't that safe and stable, you could choose:
|
||||
|
||||
> make stable-release
|
||||
>
|
||||
> mingw32-make stable-release-mingw
|
||||
|
||||
We are trying to make this project compilable on MSVC, let's wait and see.
|
||||
|
||||
## __How to Use__
|
||||
|
||||
First we should learn how to write and run a program using this language,
|
||||
|
|
|
@ -110,11 +110,11 @@ __Windows用户请一定一定一定要使用MinGW编译!__
|
|||
|
||||
__`Windows`__(`MinGW-w64`)用户使用g++编译器并使用以下命令来进行编译. 没有编译环境的请在[__这里__](https://www.mingw-w64.org/downloads/)下载MinGW-w64。(编译不出来别怪我没说哦👿)
|
||||
|
||||
> g++ -std=c++11 -O3 main.cpp -o nasal.exe -fno-exceptions -static
|
||||
> $(CXX) -std=c++11 -O3 main.cpp -o nasal.exe -fno-exceptions -static
|
||||
|
||||
__`linux/macOS/Unix`__ 用户可以使用g++或者clang++替代下面命令中中括号的部分来进行编译。
|
||||
__`linux/macOS/Unix`__ 用户可以使用g++或者clang++替代下面命令中中括号的部分来进行编译(我们建议您使用clang)。
|
||||
|
||||
> [cpp compiler] -std=c++11 -O3 main.cpp -o nasal -fno-exceptions -ldl
|
||||
> $(CXX) -std=c++11 -O3 main.cpp -o nasal -fno-exceptions -ldl
|
||||
|
||||
当然也可以使用makefile,`mingw32-make`是 __`Windows(MinGW-w64)`__ 平台的`make`:
|
||||
|
||||
|
@ -126,6 +126,22 @@ __`linux/macOS/Unix`__ 平台直接使用make即可:
|
|||
|
||||
> make nasal
|
||||
|
||||
你也可以通过在命令后面添加如下的其中一行来指定你想要使用的编译器:
|
||||
|
||||
> CXX=clang++
|
||||
>
|
||||
> CXX=g++
|
||||
>
|
||||
> CXX=...
|
||||
|
||||
如果你觉得`-O3`编译的版本不是那么安全和稳定,你也可以选择生成稳定的版本:
|
||||
|
||||
> make stable-release
|
||||
>
|
||||
> mingw32-make stable-release-mingw
|
||||
|
||||
我们现在还在尝试将项目移植到MSVC下,敬请期待。
|
||||
|
||||
## __使用方法__
|
||||
|
||||
首先我们要通过[__教程__](#教程)知道这个语言的语法以及如何使用这个解释器来运行nasal程序。
|
||||
|
|
10
makefile
10
makefile
|
@ -16,9 +16,15 @@ SRC=\
|
|||
nasal.h
|
||||
|
||||
nasal:$(SRC)
|
||||
clang++ -std=c++11 -O3 main.cpp -o nasal -fno-exceptions -ldl -Wshadow -Wall
|
||||
$(CXX) -std=c++11 -O3 main.cpp -o nasal -fno-exceptions -ldl -Wshadow -Wall
|
||||
nasal.exe:$(SRC)
|
||||
g++ -std=c++11 -O3 main.cpp -o nasal.exe -fno-exceptions -Wshadow -Wall -static
|
||||
$(CXX) -std=c++11 -O3 main.cpp -o nasal.exe -fno-exceptions -Wshadow -Wall -static
|
||||
|
||||
stable-release:$(SRC)
|
||||
$(CXX) -std=c++11 -O2 main.cpp -o nasal -fno-exceptions -ldl -Wshadow -Wall
|
||||
stable-release-mingw:$(SRC)
|
||||
$(CXX) -std=c++11 -O2 main.cpp -o nasal.exe -fno-exceptions -Wshadow -Wall -static
|
||||
|
||||
test:nasal
|
||||
@ ./nasal -op -e test/ascii-art.nas
|
||||
@ ./nasal -op -c test/auto_crash.nas
|
||||
|
|
|
@ -1,29 +1,29 @@
|
|||
.PHONY=clean all mingw-all
|
||||
libfib.so: fib.cpp
|
||||
clang++ -c -O3 fib.cpp -fPIC -o fib.o
|
||||
clang++ -shared -o libfib.so fib.o
|
||||
$(CXX) -c -O3 fib.cpp -fPIC -o fib.o
|
||||
$(CXX) -shared -o libfib.so fib.o
|
||||
rm fib.o
|
||||
libfib.dll: fib.cpp
|
||||
g++ -c -O3 fib.cpp -fPIC -o fib.o
|
||||
g++ -shared -o libfib.dll fib.o
|
||||
$(CXX) -c -O3 fib.cpp -fPIC -o fib.o
|
||||
$(CXX) -shared -o libfib.dll fib.o
|
||||
del fib.o
|
||||
|
||||
libkey.so: keyboard.cpp
|
||||
clang++ -c -O3 keyboard.cpp -fPIC -o keyboard.o
|
||||
clang++ -shared -o libkey.so keyboard.o
|
||||
$(CXX) -c -O3 keyboard.cpp -fPIC -o keyboard.o
|
||||
$(CXX) -shared -o libkey.so keyboard.o
|
||||
rm keyboard.o
|
||||
libkey.dll: keyboard.cpp
|
||||
g++ -c -O3 keyboard.cpp -fPIC -o keyboard.o -static
|
||||
g++ -shared -o libkey.dll keyboard.o -static
|
||||
$(CXX) -c -O3 keyboard.cpp -fPIC -o keyboard.o -static
|
||||
$(CXX) -shared -o libkey.dll keyboard.o -static
|
||||
del keyboard.o
|
||||
|
||||
libnasock.so: nasocket.cpp
|
||||
clang++ -c -O3 nasocket.cpp -fPIC -o nasocket.o
|
||||
clang++ -shared -o libnasock.so nasocket.o
|
||||
$(CXX) -c -O3 nasocket.cpp -fPIC -o nasocket.o
|
||||
$(CXX) -shared -o libnasock.so nasocket.o
|
||||
rm nasocket.o
|
||||
libnasock.dll: nasocket.cpp
|
||||
g++ -c -O3 nasocket.cpp -fPIC -o nasocket.o -lwsock32 -static
|
||||
g++ -shared -o libnasock.dll nasocket.o -lwsock32 -static
|
||||
$(CXX) -c -O3 nasocket.cpp -fPIC -o nasocket.o -lwsock32 -static
|
||||
$(CXX) -shared -o libnasock.dll nasocket.o -lwsock32 -static
|
||||
del nasocket.o
|
||||
|
||||
clean:
|
||||
|
@ -31,4 +31,4 @@ clean:
|
|||
all: libfib.so libkey.so libnasock.so
|
||||
@ echo "build done"
|
||||
mingw-all: libfib.dll libkey.dll libnasock.dll
|
||||
@ echo "build done"
|
||||
@ echo build done
|
|
@ -1,5 +1,4 @@
|
|||
#include "../nasal.h"
|
||||
#include <unistd.h>
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <winsock.h>
|
||||
|
|
5
nasal.h
5
nasal.h
|
@ -7,6 +7,11 @@
|
|||
#include <dirent.h>
|
||||
#endif
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#include <io.h>
|
||||
#include <direct.h>
|
||||
#endif
|
||||
|
||||
#include <cstdint>
|
||||
#include <cstdlib>
|
||||
#include <cstdio>
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
#ifndef __NASAL_AST_H__
|
||||
#ifndef __NASAL_AST_H__
|
||||
#define __NASAL_AST_H__
|
||||
|
||||
enum ast_node
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
#ifndef __NASAL_BUILTIN_H__
|
||||
#ifndef __NASAL_BUILTIN_H__
|
||||
#define __NASAL_BUILTIN_H__
|
||||
|
||||
#if defined __APPLE__
|
||||
|
@ -1030,16 +1030,28 @@ nasal_ref builtin_waitpid(nasal_ref* local,nasal_gc& gc)
|
|||
}
|
||||
void obj_dir_destructor(void* ptr)
|
||||
{
|
||||
#ifndef _MSC_VER
|
||||
closedir((DIR*)ptr);
|
||||
#else
|
||||
FindClose(ptr);
|
||||
#endif
|
||||
}
|
||||
nasal_ref builtin_opendir(nasal_ref* local,nasal_gc& gc)
|
||||
{
|
||||
nasal_ref path=local[1];
|
||||
if(path.type!=vm_str)
|
||||
return builtin_err("opendir","\"path\" must be string");
|
||||
#ifdef _MSC_VER
|
||||
WIN32_FIND_DATA data;
|
||||
HANDLE p;
|
||||
p=FindFirstFile(path.str().c_str(),&data);
|
||||
if(p==INVALID_HANDLE_VALUE)
|
||||
return builtin_err("opendir","cannot open dir <"+path.str()+"> errno "+std::to_string(errno));
|
||||
#else
|
||||
DIR* p=opendir(path.str().c_str());
|
||||
if(!p)
|
||||
return builtin_err("opendir","cannot open dir <"+path.str()+"> errno "+std::to_string(errno));
|
||||
#endif
|
||||
nasal_ref ret=gc.alloc(vm_obj);
|
||||
ret.obj().type=nasal_obj::dir;
|
||||
ret.obj().ptr=(void*)p;
|
||||
|
@ -1051,17 +1063,28 @@ nasal_ref builtin_readdir(nasal_ref* local,nasal_gc& gc)
|
|||
nasal_ref handle=local[1];
|
||||
if(!handle.objchk(nasal_obj::dir))
|
||||
return builtin_err("readdir","not a valid dir handle");
|
||||
#ifdef _MSC_VER
|
||||
WIN32_FIND_DATA data;
|
||||
if(!FindNextFile(handle.obj().ptr,&data))
|
||||
return nil;
|
||||
return gc.newstr(data.cFileName);
|
||||
#else
|
||||
dirent* p=readdir((DIR*)handle.obj().ptr);
|
||||
if(!p)
|
||||
return nil;
|
||||
return gc.newstr(p->d_name);
|
||||
#endif
|
||||
}
|
||||
nasal_ref builtin_closedir(nasal_ref* local,nasal_gc& gc)
|
||||
{
|
||||
nasal_ref handle=local[1];
|
||||
if(!handle.objchk(nasal_obj::dir))
|
||||
return builtin_err("closedir","not a valid dir handle");
|
||||
#ifndef _MSC_VER
|
||||
closedir((DIR*)handle.obj().ptr);
|
||||
#else
|
||||
FindClose(handle.obj().ptr);
|
||||
#endif
|
||||
handle.obj().ptr=nullptr;
|
||||
return nil;
|
||||
}
|
||||
|
|
|
@ -255,7 +255,7 @@ void nasal_dbg::run(
|
|||
&nasal_dbg::opr_mcallv, &nasal_dbg::opr_mcallh,
|
||||
&nasal_dbg::opr_ret
|
||||
};
|
||||
std::vector<const nafunc> code;
|
||||
std::vector<nafunc> code;
|
||||
for(auto& i:gen.get_code())
|
||||
{
|
||||
code.push_back(oprs[i.op]);
|
||||
|
|
|
@ -1,6 +1,10 @@
|
|||
#ifndef __NASAL_IMPORT_H__
|
||||
#define __NASAL_IMPORT_H__
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#define F_OK 0
|
||||
#endif
|
||||
|
||||
class nasal_import
|
||||
{
|
||||
private:
|
||||
|
|
|
@ -1,6 +1,10 @@
|
|||
#ifndef __NASAL_LEXER_H__
|
||||
#define __NASAL_LEXER_H__
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#define S_ISREG(m) (((m)&0xF000)==0x8000)
|
||||
#endif
|
||||
|
||||
#define ID(c) ((c=='_')||('a'<=c && c<='z')||('A'<=c&&c<='Z')||(c<0))
|
||||
#define HEX(c) (('0'<=c&&c<='9')||('a'<=c&&c<='f')||('A'<=c && c<='F'))
|
||||
#define OCT(c) ('0'<=c&&c<='7')
|
||||
|
|
15
nasal_vm.h
15
nasal_vm.h
|
@ -732,7 +732,11 @@ inline void nasal_vm::opr_callfv()
|
|||
for(uint32_t i=psize;i<argc;++i)
|
||||
dynamic.vec().elems.push_back(local[i]);
|
||||
}
|
||||
#ifdef _MSC_VER
|
||||
uint32_t min_size=(std::min)(psize,argc);
|
||||
#else
|
||||
uint32_t min_size=std::min(psize,argc);
|
||||
#endif
|
||||
for(uint32_t i=min_size;i>=1;--i)// load arguments
|
||||
local[i]=local[i-1];
|
||||
local[0]=func.local[0];// load "me"
|
||||
|
@ -1040,15 +1044,16 @@ void nasal_vm::run(
|
|||
&nasal_vm::opr_mcallv, &nasal_vm::opr_mcallh,
|
||||
&nasal_vm::opr_ret
|
||||
};
|
||||
std::vector<const nafunc> code;
|
||||
typedef struct{nafunc ptr;uint32_t type;} naf;
|
||||
std::vector<naf> code;
|
||||
for(auto& i:gen.get_code())
|
||||
{
|
||||
code.push_back(oprs[i.op]);
|
||||
code.push_back({oprs[i.op],i.op});
|
||||
imm.push_back(i.num);
|
||||
}
|
||||
while(code[pc]){
|
||||
(this->*code[pc])();
|
||||
++count[num];
|
||||
while(code[pc].ptr){
|
||||
++count[code[pc].type];
|
||||
(this->*code[pc].ptr)();
|
||||
if(top>=canary)
|
||||
break;
|
||||
++pc;
|
||||
|
|
Loading…
Reference in New Issue