⚡ optimize header file, now modules could generate smaller dynamic libs.
This commit is contained in:
parent
987d3ce9e2
commit
a91826607c
12
main.cpp
12
main.cpp
|
@ -1,4 +1,16 @@
|
|||
#include "nasal.h"
|
||||
#include "nasal_err.h"
|
||||
#include "nasal_lexer.h"
|
||||
#include "nasal_ast.h"
|
||||
#include "nasal_parse.h"
|
||||
#include "nasal_import.h"
|
||||
#include "nasal_opt.h"
|
||||
#include "nasal_gc.h"
|
||||
#include "nasal_builtin.h"
|
||||
#include "nasal_codegen.h"
|
||||
#include "nasal_vm.h"
|
||||
#include "nasal_dbg.h"
|
||||
#include <unordered_map>
|
||||
|
||||
const u32 VM_LEXINFO =0x01;
|
||||
const u32 VM_ASTINFO =0x02;
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
#include <iostream>
|
||||
#include "../nasal.h"
|
||||
#include "../nasal_gc.h"
|
||||
|
||||
double fibonaci(double x){
|
||||
if(x<=2)
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
#include "../nasal.h"
|
||||
#include "../nasal_gc.h"
|
||||
#include <unistd.h>
|
||||
#include <iostream>
|
||||
#ifdef _WIN32
|
||||
#include <conio.h>
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
#include "../nasal.h"
|
||||
#include "../nasal_gc.h"
|
||||
#include <unistd.h>
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <winsock.h>
|
||||
|
|
42
nasal.h
42
nasal.h
|
@ -2,43 +2,12 @@
|
|||
#define __NASAL_H__
|
||||
#define __nasver "10.1"
|
||||
|
||||
#ifndef _MSC_VER
|
||||
#include <unistd.h>
|
||||
#include <dirent.h>
|
||||
#else
|
||||
#include <io.h>
|
||||
#include <direct.h>
|
||||
#endif
|
||||
|
||||
#include <cstdint>
|
||||
#include <cstdlib>
|
||||
#include <cstdio>
|
||||
#include <iostream>
|
||||
#include <iomanip>
|
||||
#include <fstream>
|
||||
#include <sstream>
|
||||
#include <algorithm>
|
||||
#include <cstring>
|
||||
#include <cstdlib>
|
||||
#include <ctime>
|
||||
#include <cmath>
|
||||
#include <list>
|
||||
#include <stack>
|
||||
#include <queue>
|
||||
#include <vector>
|
||||
#include <unordered_map>
|
||||
#include <thread>
|
||||
#include <chrono>
|
||||
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <windows.h>
|
||||
#else
|
||||
#include <dlfcn.h>
|
||||
#include <sys/wait.h>
|
||||
#endif
|
||||
|
||||
using i32=std::int32_t;
|
||||
using i64=std::int64_t;
|
||||
|
@ -184,16 +153,5 @@ string rawstr(const string& str,const usize maxlen=0)
|
|||
ret=ret.substr(0,maxlen)+"...";
|
||||
return ret;
|
||||
}
|
||||
#include "nasal_err.h"
|
||||
#include "nasal_lexer.h"
|
||||
#include "nasal_ast.h"
|
||||
#include "nasal_parse.h"
|
||||
#include "nasal_import.h"
|
||||
#include "nasal_opt.h"
|
||||
#include "nasal_gc.h"
|
||||
#include "nasal_builtin.h"
|
||||
#include "nasal_codegen.h"
|
||||
#include "nasal_vm.h"
|
||||
#include "nasal_dbg.h"
|
||||
|
||||
#endif
|
||||
|
|
|
@ -1,17 +1,33 @@
|
|||
#ifndef __NASAL_BUILTIN_H__
|
||||
#define __NASAL_BUILTIN_H__
|
||||
|
||||
#include "nasal_gc.h"
|
||||
|
||||
#ifndef _MSC_VER
|
||||
#include <unistd.h>
|
||||
#include <dirent.h>
|
||||
#else
|
||||
#include <io.h>
|
||||
#include <direct.h>
|
||||
#endif
|
||||
|
||||
#include <sstream>
|
||||
#include <cmath>
|
||||
#include <thread>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <windows.h>
|
||||
#else
|
||||
#include <dlfcn.h>
|
||||
#include <sys/wait.h>
|
||||
#endif
|
||||
|
||||
#if defined __APPLE__
|
||||
#include <crt_externs.h>
|
||||
#define environ (*_NSGetEnviron())
|
||||
#endif
|
||||
|
||||
nas_ref nas_err(const string& err_f,const string& info)
|
||||
{
|
||||
std::cerr<<"[vm] "<<err_f<<": "<<info<<"\n";
|
||||
return {vm_none};
|
||||
}
|
||||
|
||||
void print_core(std::vector<nas_ref>& elems)
|
||||
{
|
||||
for(auto& i:elems)
|
||||
|
|
|
@ -1,6 +1,11 @@
|
|||
#ifndef __NASAL_CODEGEN_H__
|
||||
#define __NASAL_CODEGEN_H__
|
||||
|
||||
#include <iomanip>
|
||||
#include <list>
|
||||
#include <stack>
|
||||
#include <unordered_map>
|
||||
|
||||
enum op_code:u8
|
||||
{
|
||||
op_exit, // stop the virtual machine
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
#define __NASAL_DBG_H__
|
||||
|
||||
#include "nasal_vm.h"
|
||||
#include <algorithm>
|
||||
|
||||
class nasal_dbg:public nasal_vm
|
||||
{
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <sstream> // MSVC need this to use std::getline
|
||||
#include <cstring>
|
||||
|
||||
class fstreamline
|
||||
|
|
10
nasal_gc.h
10
nasal_gc.h
|
@ -1,6 +1,9 @@
|
|||
#ifndef __NASAL_GC_H__
|
||||
#define __NASAL_GC_H__
|
||||
|
||||
#include <queue>
|
||||
#include <unordered_map>
|
||||
|
||||
enum vm_type:u8{
|
||||
/* none-gc object */
|
||||
vm_none=0,
|
||||
|
@ -714,4 +717,11 @@ void nasal_gc::ctxreserve()
|
|||
stack=mctx.stack;
|
||||
cort=nullptr;
|
||||
}
|
||||
|
||||
// use to print error log and return error value
|
||||
nas_ref nas_err(const string& err_f,const string& info)
|
||||
{
|
||||
std::cerr<<"[vm] "<<err_f<<": "<<info<<"\n";
|
||||
return {vm_none};
|
||||
}
|
||||
#endif
|
|
@ -1,6 +1,12 @@
|
|||
#ifndef __NASAL_IMPORT_H__
|
||||
#define __NASAL_IMPORT_H__
|
||||
|
||||
#ifndef _MSC_VER
|
||||
#include <unistd.h>
|
||||
#else
|
||||
#include <io.h>
|
||||
#endif
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#define F_OK 0
|
||||
#endif
|
||||
|
|
|
@ -1,6 +1,9 @@
|
|||
#ifndef __NASAL_LEXER_H__
|
||||
#define __NASAL_LEXER_H__
|
||||
|
||||
#include <sstream>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#define S_ISREG(m) (((m)&0xF000)==0x8000)
|
||||
#endif
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
#ifndef __NASAL_OPT_H__
|
||||
#define __NASAL_OPT_H__
|
||||
|
||||
#include <cmath>
|
||||
|
||||
void const_str(nasal_ast& root)
|
||||
{
|
||||
auto& vec=root.child();
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
#ifndef __NASAL_PARSE_H__
|
||||
#define __NASAL_PARSE_H__
|
||||
|
||||
#include <unordered_map>
|
||||
|
||||
/*
|
||||
_,,,_
|
||||
.' `'.
|
||||
|
|
|
@ -1,6 +1,9 @@
|
|||
#ifndef __NASAL_VM_H__
|
||||
#define __NASAL_VM_H__
|
||||
|
||||
#include <iomanip>
|
||||
#include <stack>
|
||||
|
||||
class nasal_vm
|
||||
{
|
||||
protected:
|
||||
|
|
Loading…
Reference in New Issue