📝 change identifiers' name
This commit is contained in:
parent
d904123695
commit
cfbec9a3f1
5
nasal.h
5
nasal.h
|
@ -5,9 +5,7 @@
|
||||||
#ifndef _MSC_VER
|
#ifndef _MSC_VER
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <dirent.h>
|
#include <dirent.h>
|
||||||
#endif
|
#else
|
||||||
|
|
||||||
#ifdef _MSC_VER
|
|
||||||
#include <io.h>
|
#include <io.h>
|
||||||
#include <direct.h>
|
#include <direct.h>
|
||||||
#endif
|
#endif
|
||||||
|
@ -34,7 +32,6 @@
|
||||||
|
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <sys/timeb.h>
|
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
|
|
|
@ -310,9 +310,9 @@ public:
|
||||||
nasal_codegen(nasal_err& e):fileindex(0),nerr(e),file(nullptr){}
|
nasal_codegen(nasal_err& e):fileindex(0),nerr(e),file(nullptr){}
|
||||||
void compile(const nasal_parse&,const nasal_import&);
|
void compile(const nasal_parse&,const nasal_import&);
|
||||||
void print();
|
void print();
|
||||||
const std::vector<std::string>& get_strs() const {return str_res;}
|
const std::vector<std::string>& strs() const {return str_res;}
|
||||||
const std::vector<double>& get_nums() const {return num_res;}
|
const std::vector<double>& nums() const {return num_res;}
|
||||||
const std::vector<opcode>& get_code() const {return code;}
|
const std::vector<opcode>& codes() const {return code;}
|
||||||
};
|
};
|
||||||
|
|
||||||
void nasal_codegen::die(const std::string& info,const uint32_t line)
|
void nasal_codegen::die(const std::string& info,const uint32_t line)
|
||||||
|
@ -1282,7 +1282,7 @@ void nasal_codegen::ret_gen(const nasal_ast& ast)
|
||||||
void nasal_codegen::compile(const nasal_parse& parse,const nasal_import& import)
|
void nasal_codegen::compile(const nasal_parse& parse,const nasal_import& import)
|
||||||
{
|
{
|
||||||
fileindex=0;
|
fileindex=0;
|
||||||
file=import.get_file().data();
|
file=import.filelist().data();
|
||||||
in_iterloop.push(0);
|
in_iterloop.push(0);
|
||||||
|
|
||||||
regist_num(0);
|
regist_num(0);
|
||||||
|
|
|
@ -179,8 +179,8 @@ void nasal_dbg::run(
|
||||||
const std::vector<std::string>& argv)
|
const std::vector<std::string>& argv)
|
||||||
{
|
{
|
||||||
detail_info=true;
|
detail_info=true;
|
||||||
fsize=linker.get_file().size();
|
fsize=linker.filelist().size();
|
||||||
init(gen.get_strs(),gen.get_nums(),gen.get_code(),linker.get_file(),argv);
|
init(gen.strs(),gen.nums(),gen.codes(),linker.filelist(),argv);
|
||||||
#ifndef _MSC_VER
|
#ifndef _MSC_VER
|
||||||
const void* oprs[]=
|
const void* oprs[]=
|
||||||
{
|
{
|
||||||
|
@ -205,7 +205,7 @@ void nasal_dbg::run(
|
||||||
&&mcallv, &&mcallh, &&ret
|
&&mcallv, &&mcallh, &&ret
|
||||||
};
|
};
|
||||||
std::vector<const void*> code;
|
std::vector<const void*> code;
|
||||||
for(auto& i:gen.get_code())
|
for(auto& i:gen.codes())
|
||||||
{
|
{
|
||||||
code.push_back(oprs[i.op]);
|
code.push_back(oprs[i.op]);
|
||||||
imm.push_back(i.num);
|
imm.push_back(i.num);
|
||||||
|
@ -256,7 +256,7 @@ void nasal_dbg::run(
|
||||||
&nasal_dbg::opr_ret
|
&nasal_dbg::opr_ret
|
||||||
};
|
};
|
||||||
std::vector<nafunc> code;
|
std::vector<nafunc> code;
|
||||||
for(auto& i:gen.get_code())
|
for(auto& i:gen.codes())
|
||||||
{
|
{
|
||||||
code.push_back(oprs[i.op]);
|
code.push_back(oprs[i.op]);
|
||||||
imm.push_back(i.num);
|
imm.push_back(i.num);
|
||||||
|
|
|
@ -22,7 +22,7 @@ private:
|
||||||
public:
|
public:
|
||||||
nasal_import(nasal_err&);
|
nasal_import(nasal_err&);
|
||||||
void link(nasal_parse&,const std::string&);
|
void link(nasal_parse&,const std::string&);
|
||||||
const std::vector<std::string>& get_file() const {return files;}
|
const std::vector<std::string>& filelist() const {return files;}
|
||||||
};
|
};
|
||||||
|
|
||||||
nasal_import::nasal_import(nasal_err& e):lib_loaded(false),nerr(e){
|
nasal_import::nasal_import(nasal_err& e):lib_loaded(false),nerr(e){
|
||||||
|
|
30
nasal_vm.h
30
nasal_vm.h
|
@ -678,10 +678,10 @@ inline void nasal_vm::opr_callv()
|
||||||
{
|
{
|
||||||
std::string& str=vec.str();
|
std::string& str=vec.str();
|
||||||
int num=val.tonum();
|
int num=val.tonum();
|
||||||
int str_size=str.length();
|
int len=str.length();
|
||||||
if(num<-str_size || num>=str_size)
|
if(num<-len || num>=len)
|
||||||
die("callv: index out of range:"+std::to_string(val.tonum()));
|
die("callv: index out of range:"+std::to_string(val.tonum()));
|
||||||
top[0]={vm_num,double((uint8_t)str[num>=0? num:num+str_size])};
|
top[0]={vm_num,double((uint8_t)str[num>=0? num:num+len])};
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
die("callv: must call a vector/hash/string");
|
die("callv: must call a vector/hash/string");
|
||||||
|
@ -745,7 +745,8 @@ inline void nasal_vm::opr_callfv()
|
||||||
for(uint32_t i=min_size;i>=1;--i)// load arguments
|
for(uint32_t i=min_size;i>=1;--i)// load arguments
|
||||||
local[i]=local[i-1];
|
local[i]=local[i-1];
|
||||||
local[0]=func.local[0];// load "me"
|
local[0]=func.local[0];// load "me"
|
||||||
for(uint32_t i=min_size+1;i<func.lsize;++i)// load local scope & default arguments
|
// load local scope & default arguments
|
||||||
|
for(uint32_t i=min_size+1;i<func.lsize;++i)
|
||||||
local[i]=func.local[i];
|
local[i]=func.local[i];
|
||||||
if(func.dynpara>=0)
|
if(func.dynpara>=0)
|
||||||
local[psize+1]=dynamic;
|
local[psize+1]=dynamic;
|
||||||
|
@ -803,7 +804,7 @@ inline void nasal_vm::opr_callb()
|
||||||
// (top) will be set to another context.top, instead of main_context.top
|
// (top) will be set to another context.top, instead of main_context.top
|
||||||
top[0]=(*builtin[imm[pc]].func)(localr,gc);
|
top[0]=(*builtin[imm[pc]].func)(localr,gc);
|
||||||
if(top[0].type==vm_none)
|
if(top[0].type==vm_none)
|
||||||
die("native function error.");
|
die("native function error");
|
||||||
}
|
}
|
||||||
inline void nasal_vm::opr_slcbeg()
|
inline void nasal_vm::opr_slcbeg()
|
||||||
{
|
{
|
||||||
|
@ -814,7 +815,7 @@ inline void nasal_vm::opr_slcbeg()
|
||||||
// +--------------+
|
// +--------------+
|
||||||
(++top)[0]=gc.alloc(vm_vec);
|
(++top)[0]=gc.alloc(vm_vec);
|
||||||
if(top[-1].type!=vm_vec)
|
if(top[-1].type!=vm_vec)
|
||||||
die("slcbegin: must slice a vector");
|
die("slcbeg: must slice a vector");
|
||||||
}
|
}
|
||||||
inline void nasal_vm::opr_slcend()
|
inline void nasal_vm::opr_slcend()
|
||||||
{
|
{
|
||||||
|
@ -973,7 +974,7 @@ void nasal_vm::run(
|
||||||
const bool detail)
|
const bool detail)
|
||||||
{
|
{
|
||||||
detail_info=detail;
|
detail_info=detail;
|
||||||
init(gen.get_strs(),gen.get_nums(),gen.get_code(),linker.get_file(),argv);
|
init(gen.strs(),gen.nums(),gen.codes(),linker.filelist(),argv);
|
||||||
uint64_t count[op_ret+1]={0};
|
uint64_t count[op_ret+1]={0};
|
||||||
#ifndef _MSC_VER
|
#ifndef _MSC_VER
|
||||||
const void* oprs[]=
|
const void* oprs[]=
|
||||||
|
@ -999,7 +1000,7 @@ void nasal_vm::run(
|
||||||
&&mcallv, &&mcallh, &&ret
|
&&mcallv, &&mcallh, &&ret
|
||||||
};
|
};
|
||||||
std::vector<const void*> code;
|
std::vector<const void*> code;
|
||||||
for(auto& i:gen.get_code())
|
for(auto& i:gen.codes())
|
||||||
{
|
{
|
||||||
code.push_back(oprs[i.op]);
|
code.push_back(oprs[i.op]);
|
||||||
imm.push_back(i.num);
|
imm.push_back(i.num);
|
||||||
|
@ -1049,16 +1050,15 @@ void nasal_vm::run(
|
||||||
&nasal_vm::opr_mcallv, &nasal_vm::opr_mcallh,
|
&nasal_vm::opr_mcallv, &nasal_vm::opr_mcallh,
|
||||||
&nasal_vm::opr_ret
|
&nasal_vm::opr_ret
|
||||||
};
|
};
|
||||||
typedef struct{nafunc ptr;uint32_t type;} naf;
|
std::vector<uint32_t> code;
|
||||||
std::vector<naf> code;
|
for(auto& i:gen.codes())
|
||||||
for(auto& i:gen.get_code())
|
|
||||||
{
|
{
|
||||||
code.push_back({oprs[i.op],i.op});
|
code.push_back(i.op);
|
||||||
imm.push_back(i.num);
|
imm.push_back(i.num);
|
||||||
}
|
}
|
||||||
while(code[pc].ptr){
|
while(oprs[code[pc]]){
|
||||||
++count[code[pc].type];
|
++count[code[pc]];
|
||||||
(this->*code[pc].ptr)();
|
(this->*oprs[code[pc]])();
|
||||||
if(top>=canary)
|
if(top>=canary)
|
||||||
break;
|
break;
|
||||||
++pc;
|
++pc;
|
||||||
|
|
Loading…
Reference in New Issue