no more implicit returning in programs and mdouels

This commit is contained in:
2026-02-23 19:01:58 -06:00
parent 6812d3edbc
commit 124c9536b4
3 changed files with 60 additions and 17 deletions

View File

@@ -3103,7 +3103,6 @@ var mcode = function(ast) {
var local_slot = 0
var dest = 0
var statements = ast.statements
var last_expr_slot = -1
var stmt = null
var kind = null
var null_slot = 0
@@ -3170,21 +3169,18 @@ var mcode = function(ast) {
kind = stmt.kind
if (kind != null) {
if (kind == "call") {
last_expr_slot = gen_expr(stmt.expression, -1)
gen_expr(stmt.expression, -1)
} else if (kind == "return" || kind == "disrupt" ||
kind == "break" || kind == "continue") {
gen_statement(stmt)
last_expr_slot = -1
} else if (kind == "var" || kind == "def" ||
kind == "break" || kind == "continue" ||
kind == "var" || kind == "def" ||
kind == "var_list" || kind == "def_list" ||
kind == "function" || kind == "block" ||
kind == "if" || kind == "while" ||
kind == "do" || kind == "for" ||
kind == "switch") {
gen_statement(stmt)
last_expr_slot = -1
} else {
last_expr_slot = gen_expr(stmt, -1)
gen_expr(stmt, -1)
}
} else {
gen_statement(stmt)
@@ -3192,13 +3188,9 @@ var mcode = function(ast) {
_i = _i + 1
}
if (last_expr_slot >= 0) {
emit_1("return", last_expr_slot)
} else {
null_slot = alloc_slot()
emit_1("null", null_slot)
emit_1("return", null_slot)
}
null_slot = alloc_slot()
emit_1("null", null_slot)
emit_1("return", null_slot)
result = {}
result.name = filename != null ? filename : "<eval>"