rm push/pop
This commit is contained in:
55
mcode.cm
55
mcode.cm
@@ -166,7 +166,7 @@ var mcode = function(ast) {
|
||||
|
||||
// Variable tracking
|
||||
var add_var = function(name, slot, is_const) {
|
||||
push(s_vars, {name: name, slot: slot, is_const: is_const, is_closure: false})
|
||||
s_vars[] = {name: name, slot: slot, is_const: is_const, is_closure: false}
|
||||
}
|
||||
|
||||
var find_var = function(name) {
|
||||
@@ -228,13 +228,13 @@ var mcode = function(ast) {
|
||||
|
||||
// Instruction emission
|
||||
var add_instr = function(instr) {
|
||||
push(instr, s_cur_line)
|
||||
push(instr, s_cur_col)
|
||||
push(s_instructions, instr)
|
||||
instr[] = s_cur_line
|
||||
instr[] = s_cur_col
|
||||
s_instructions[] = instr
|
||||
}
|
||||
|
||||
var emit_label = function(label) {
|
||||
push(s_instructions, label)
|
||||
s_instructions[] = label
|
||||
}
|
||||
|
||||
var emit_0 = function(op) {
|
||||
@@ -743,7 +743,7 @@ var mcode = function(ast) {
|
||||
slot = alloc_slot()
|
||||
lit = {kind: "name", name: name, make: "intrinsic"}
|
||||
add_instr(["access", slot, lit])
|
||||
push(s_intrinsic_cache, {name: name, slot: slot})
|
||||
s_intrinsic_cache[] = {name: name, slot: slot}
|
||||
_i = _i + 1
|
||||
}
|
||||
}
|
||||
@@ -1974,7 +1974,7 @@ var mcode = function(ast) {
|
||||
expr_slots = []
|
||||
_i = 0
|
||||
while (_i < nexpr) {
|
||||
push(expr_slots, gen_expr(list[_i], -1))
|
||||
expr_slots[] = gen_expr(list[_i], -1)
|
||||
_i = _i + 1
|
||||
}
|
||||
// Create array from expression results
|
||||
@@ -2083,6 +2083,23 @@ var mcode = function(ast) {
|
||||
if (kind == "[") {
|
||||
obj = expr.left
|
||||
idx = expr.right
|
||||
if (idx == null) {
|
||||
// arr[] pop expression
|
||||
obj_slot = gen_expr(obj, -1)
|
||||
guard_t = alloc_slot()
|
||||
guard_err = gen_label("pop_err")
|
||||
guard_done = gen_label("pop_done")
|
||||
emit_2("is_array", guard_t, obj_slot)
|
||||
emit_jump_cond("jump_false", guard_t, guard_err)
|
||||
slot = target >= 0 ? target : alloc_slot()
|
||||
emit_2("pop", slot, obj_slot)
|
||||
emit_jump(guard_done)
|
||||
emit_label(guard_err)
|
||||
emit_log_error("cannot pop: target must be an array")
|
||||
emit_0("disrupt")
|
||||
emit_label(guard_done)
|
||||
return slot
|
||||
}
|
||||
obj_slot = gen_expr(obj, -1)
|
||||
idx_slot = gen_expr(idx, -1)
|
||||
slot = alloc_slot()
|
||||
@@ -2264,7 +2281,7 @@ var mcode = function(ast) {
|
||||
_i = 0
|
||||
nargs = args_list != null ? length(args_list) : 0
|
||||
while (_i < nargs) {
|
||||
push(arg_slots, gen_expr(args_list[_i], -1))
|
||||
arg_slots[] = gen_expr(args_list[_i], -1)
|
||||
_i = _i + 1
|
||||
}
|
||||
dest = alloc_slot()
|
||||
@@ -2432,7 +2449,7 @@ var mcode = function(ast) {
|
||||
elem_slots = []
|
||||
_i = 0
|
||||
while (_i < count) {
|
||||
push(elem_slots, gen_expr(list[_i], -1))
|
||||
elem_slots[] = gen_expr(list[_i], -1)
|
||||
_i = _i + 1
|
||||
}
|
||||
dest = alloc_slot()
|
||||
@@ -2449,7 +2466,7 @@ var mcode = function(ast) {
|
||||
if (kind == "record") {
|
||||
list = expr.list
|
||||
dest = alloc_slot()
|
||||
push(s_instructions, ["record", dest, length(list)])
|
||||
s_instructions[] = ["record", dest, length(list)]
|
||||
_i = 0
|
||||
while (_i < length(list)) {
|
||||
pair = list[_i]
|
||||
@@ -2479,7 +2496,7 @@ var mcode = function(ast) {
|
||||
func = gen_function(expr)
|
||||
func_id = s_func_counter
|
||||
s_func_counter = s_func_counter + 1
|
||||
push(s_functions, func)
|
||||
s_functions[] = func
|
||||
dest = alloc_slot()
|
||||
emit_2("function", dest, func_id)
|
||||
return dest
|
||||
@@ -2797,7 +2814,7 @@ var mcode = function(ast) {
|
||||
_i = 0
|
||||
nargs = args_list != null ? length(args_list) : 0
|
||||
while (_i < nargs) {
|
||||
push(arg_slots, gen_expr(args_list[_i], -1))
|
||||
arg_slots[] = gen_expr(args_list[_i], -1)
|
||||
_i = _i + 1
|
||||
}
|
||||
callee_kind = callee.kind
|
||||
@@ -2852,7 +2869,7 @@ var mcode = function(ast) {
|
||||
case_kind = case_node.kind
|
||||
if (case_kind == "default") {
|
||||
default_label = gen_label("switch_default")
|
||||
push(case_labels, default_label)
|
||||
case_labels[] = default_label
|
||||
} else {
|
||||
case_label = gen_label("switch_case")
|
||||
case_expr = case_node.expression
|
||||
@@ -2862,7 +2879,7 @@ var mcode = function(ast) {
|
||||
_bp_rn = case_expr
|
||||
emit_binop("eq", cmp_slot, switch_val, case_val)
|
||||
emit_jump_cond("jump_true", cmp_slot, case_label)
|
||||
push(case_labels, case_label)
|
||||
case_labels[] = case_label
|
||||
}
|
||||
_i = _i + 1
|
||||
}
|
||||
@@ -2894,7 +2911,7 @@ var mcode = function(ast) {
|
||||
func = gen_function(stmt)
|
||||
func_id = s_func_counter
|
||||
s_func_counter = s_func_counter + 1
|
||||
push(s_functions, func)
|
||||
s_functions[] = func
|
||||
local_slot = find_var(name)
|
||||
dest = alloc_slot()
|
||||
emit_2("function", dest, func_id)
|
||||
@@ -2948,7 +2965,7 @@ var mcode = function(ast) {
|
||||
var saved_func = 0
|
||||
var captured_this = 0
|
||||
|
||||
push(parent_states, saved)
|
||||
parent_states[] = saved
|
||||
|
||||
s_instructions = []
|
||||
s_vars = []
|
||||
@@ -3039,7 +3056,7 @@ var mcode = function(ast) {
|
||||
compiled = gen_function(fn)
|
||||
func_id = s_func_counter
|
||||
s_func_counter = s_func_counter + 1
|
||||
push(s_functions, compiled)
|
||||
s_functions[] = compiled
|
||||
local_slot = find_var(fname)
|
||||
dest = alloc_slot()
|
||||
emit_2("function", dest, func_id)
|
||||
@@ -3112,7 +3129,7 @@ var mcode = function(ast) {
|
||||
saved_func = s_func_counter
|
||||
|
||||
// Pop parent state
|
||||
pop(parent_states)
|
||||
parent_states[]
|
||||
restore_state(saved)
|
||||
s_label_counter = saved_label
|
||||
s_func_counter = saved_func
|
||||
@@ -3179,7 +3196,7 @@ var mcode = function(ast) {
|
||||
compiled = gen_function(fn)
|
||||
func_id = s_func_counter
|
||||
s_func_counter = s_func_counter + 1
|
||||
push(s_functions, compiled)
|
||||
s_functions[] = compiled
|
||||
local_slot = find_var(name)
|
||||
dest = alloc_slot()
|
||||
emit_2("function", dest, func_id)
|
||||
|
||||
Reference in New Issue
Block a user