⚡ maybe do not need o_intg anymore
This commit is contained in:
parent
93528babdb
commit
ae5c76ecd5
|
@ -7,7 +7,7 @@
|
|||
|
||||
enum op_code_type:u8 {
|
||||
op_exit, // stop the virtual machine
|
||||
op_intg, // global scope size, set stack top
|
||||
op_intg, // init global scope
|
||||
op_intl, // local scope size
|
||||
op_loadg, // load global value
|
||||
op_loadl, // load local value
|
||||
|
|
|
@ -13,6 +13,7 @@ void vm::init(
|
|||
cstr = strs.data();
|
||||
bytecode = code.data();
|
||||
files = filenames.data();
|
||||
global_size = global_symbol.size();
|
||||
|
||||
/* set native functions */
|
||||
native = natives;
|
||||
|
@ -24,7 +25,7 @@ void vm::init(
|
|||
ctx.funcr = nil;
|
||||
ctx.upvalr = nil;
|
||||
ctx.canary = ctx.stack+STACK_DEPTH-1; // stack[STACK_DEPTH-1]
|
||||
ctx.top = ctx.stack;
|
||||
ctx.top = ctx.stack; // nothing is on stack
|
||||
|
||||
/* clear main stack and global */
|
||||
for(u32 i = 0; i<STACK_DEPTH; ++i) {
|
||||
|
@ -33,7 +34,7 @@ void vm::init(
|
|||
}
|
||||
|
||||
/* init gc */
|
||||
ngc.set(&ctx, global, global_symbol.size());
|
||||
ngc.set(&ctx, global, global_size);
|
||||
ngc.init(strs, argv);
|
||||
|
||||
/* init vm globals */
|
||||
|
@ -131,7 +132,7 @@ void vm::stackinfo(const u32 limit = 10) {
|
|||
for(u32 i = 0; i<limit && top>=bottom; ++i, --top) {
|
||||
std::clog << " 0x" << std::hex
|
||||
<< std::setw(6) << std::setfill('0')
|
||||
<< (u64)(top-ngc.rctx->stack) << std::dec
|
||||
<< (u64)(top-bottom) << std::dec
|
||||
<< " ";
|
||||
valinfo(top[0]);
|
||||
}
|
||||
|
@ -152,13 +153,12 @@ void vm::reginfo() {
|
|||
}
|
||||
|
||||
void vm::gstate() {
|
||||
// bytecode[0].op is op_intg
|
||||
if (!bytecode[0].num || global[0].type==vm_none) {
|
||||
if (!global_size || global[0].type==vm_none) {
|
||||
return;
|
||||
}
|
||||
std::clog << "global (0x" << std::hex
|
||||
<< (u64)global << ")\n" << std::dec;
|
||||
for(u32 i = 0; i<bytecode[0].num; ++i) {
|
||||
for(usize i = 0; i<global_size; ++i) {
|
||||
std::clog << " 0x" << std::hex << std::setw(6)
|
||||
<< std::setfill('0') << i << std::dec
|
||||
<< " ";
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
class vm {
|
||||
protected:
|
||||
|
||||
/* registers and constants of vm */
|
||||
/* registers of vm */
|
||||
context ctx;
|
||||
|
||||
/* constants */
|
||||
|
@ -30,6 +30,7 @@ protected:
|
|||
|
||||
/* main stack */
|
||||
var* global = nullptr;
|
||||
usize global_size = 0;
|
||||
|
||||
/* values used for debugger */
|
||||
const std::string* files = nullptr; // file name list
|
||||
|
@ -180,7 +181,7 @@ inline bool vm::cond(var& val) {
|
|||
|
||||
inline void vm::o_intg() {
|
||||
// global values store on stack
|
||||
ctx.top += imm[ctx.pc];
|
||||
// ctx.top += imm[ctx.pc];
|
||||
// point to the top
|
||||
--ctx.top;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue