🔥 remove vm_cnt type
Some checks failed
Nasal Interpreter Test / mac-aarch64 (push) Has been cancelled
Nasal Interpreter Test / linux-x86_64 (push) Has been cancelled

This commit is contained in:
ValKmjolnir
2026-04-12 16:48:12 +08:00
parent cbdfcc396a
commit db9d59d030
3 changed files with 8 additions and 17 deletions

View File

@@ -15,7 +15,6 @@ namespace nasal {
enum class vm_type: u8 {
/* none-gc object */
vm_none = 0, // error type
vm_cnt, // counter for forindex/foreach loop
vm_addr, // var* address
vm_ret, // return addres(program counter)
vm_nil, // nil
@@ -81,7 +80,6 @@ public:
vm_type type = vm_type::vm_none;
union {
u64 ret;
i64 cnt;
f64 num;
var* addr;
nas_val* gcobj;
@@ -89,7 +87,6 @@ public:
private:
var(vm_type t, u64 pc) { type = t; val.ret = pc; }
var(vm_type t, i64 ct) { type = t; val.cnt = ct; }
var(vm_type t, f64 n) { type = t; val.num = n; }
var(vm_type t, var* p) { type = t; val.addr = p; }
var(vm_type t, nas_val* p) { type = t; val.gcobj = p; }
@@ -115,9 +112,6 @@ public:
static var ret(u64 pc) {
return var(vm_type::vm_ret, pc);
}
static var cnt(i64 n) {
return var(vm_type::vm_cnt, n);
}
static var num(f64 n) {
return var(vm_type::vm_num, n);
}
@@ -132,7 +126,6 @@ public:
// get value
var* addr() const { return val.addr; }
u64 ret() const { return val.ret; }
i64& cnt() { return val.cnt; }
f64 num() const { return val.num; }
public:
@@ -159,7 +152,6 @@ public:
public:
bool is_none() const { return type == vm_type::vm_none; }
bool is_cnt() const { return type == vm_type::vm_cnt; }
bool is_addr() const { return type == vm_type::vm_addr; }
bool is_ret() const { return type == vm_type::vm_ret; }
bool is_nil() const { return type == vm_type::vm_nil; }

View File

@@ -138,7 +138,6 @@ void vm::value_name_form(const var& val) {
case vm_type::vm_none: std::clog << "null "; break;
case vm_type::vm_ret: std::clog << "ret "; break;
case vm_type::vm_addr: std::clog << "addr "; break;
case vm_type::vm_cnt: std::clog << "cnt "; break;
case vm_type::vm_nil: std::clog << "nil "; break;
case vm_type::vm_num: std::clog << "num "; break;
case vm_type::vm_str: std::clog << "str "; break;
@@ -161,7 +160,6 @@ void vm::value_info(var& val) {
case vm_type::vm_none: break;
case vm_type::vm_ret: return_address_info(val); break;
case vm_type::vm_addr: memory_address_info(val); break;
case vm_type::vm_cnt: std::clog << val.cnt(); break;
case vm_type::vm_nil: break;
case vm_type::vm_num: std::clog << val.num(); break;
case vm_type::vm_str: raw_string_info(val); break;
@@ -509,7 +507,6 @@ std::string vm::report_out_of_range(f64 index, usize real_size) const {
std::string vm::type_name_string(const var& value) const {
switch(value.type) {
case vm_type::vm_none: return "none";
case vm_type::vm_cnt: return "counter";
case vm_type::vm_addr: return "address";
case vm_type::vm_ret: return "program counter";
case vm_type::vm_nil: return "nil";

View File

@@ -760,25 +760,27 @@ inline void vm::o_cnt() {
);
return;
}
(++ctx.top)[0] = var::cnt(-1);
(++ctx.top)[0] = var::num(-1.0f);
}
inline void vm::o_findex() {
if ((usize)(++ctx.top[0].cnt())>=ctx.top[-1].vec().size()) {
ctx.pc = imm[ctx.pc]-1;
ctx.top[0] = var::num(ctx.top[0].num() + 1.0f);
if ((usize)ctx.top[0].num() >= ctx.top[-1].vec().size()) {
ctx.pc = imm[ctx.pc] - 1;
return;
}
ctx.top[1] = var::num(ctx.top[0].cnt());
ctx.top[1] = ctx.top[0];
++ctx.top;
}
inline void vm::o_feach() {
ctx.top[0] = var::num(ctx.top[0].num() + 1.0f);
auto& ref = ctx.top[-1].vec().elems;
if ((usize)(++ctx.top[0].cnt())>=ref.size()) {
if ((usize)ctx.top[0].num() >= ref.size()) {
ctx.pc = imm[ctx.pc]-1;
return;
}
ctx.top[1] = ref[ctx.top[0].cnt()];
ctx.top[1] = ref[ctx.top[0].num()];
++ctx.top;
}