native x86-64 backend (pluggable, per-opcode lowering)
A second backend that lowers each bytecode instruction to a machine-code call into a runtime helper, with control flow as real branches. - cat/backend/x86_64_glue.c: one helper per opcode, mirroring cat/vm.c exactly (frame lifecycle, arith, cmp, attr/idx, call/callmethod, is, next/fornext, try/raise). Helpers use the SysV convention (f in rdi, a/b/c in rsi/rdx/rcx) and return 0/1/-1. - cat/backend/x86_64.c: emits AT&T assembly (one labelled block per instruction, one call per helper, real jumps for JUMP/JUMPIF/JUMPIFNOT/ FORNEXT/RETURN, an .Lonerror block that resumes try handlers), plus a small generated _main.c that rebuilds the bytecode and boots the VM. Builds with as + cc linked against libcatscript.a. - generators are not lowered: their prototype carries no nat_entry, so the VM runs them (their bytecode is rebuilt by the generated main), and the emitted code simply falls back to the interpreter. - cat_vm_exec_closure dispatches to a prototype's nat_entry when present. - tests: native-vs-interpreter equivalence check. Suite 155 -> 156. Verified: hello, control, classes, generators, arith, errors, text, oop, slots, reflect, toml, files, ffi all match the interpreter natively.
This commit is contained in:
1 parent
1832326a3d
commit
77ea433215
8 files changed
+1221
-48
No files matched your search
@@ -327,6 +327,36 @@ case "$out" in
|
||||
*) check "selfhost-compile-2" "sum = 42" "missing" ;;
|
||||
esac
|
||||
|
||||
# the native x86_64 backend must AGREE with the interpreter
|
||||
cat > /tmp/cat_nat_eq.cat <<'EOCAT'
|
||||
local i = 0
|
||||
local acc = 0
|
||||
while i < 5 do
|
||||
acc = acc + i * 2
|
||||
i = i + 1
|
||||
end
|
||||
print("acc", acc)
|
||||
print("cmp", 3 < 4, "a" == "a")
|
||||
local t = {}
|
||||
t.x = 7
|
||||
t["y"] = 8
|
||||
print("t", t.x + t.y)
|
||||
print("hi " .. "there")
|
||||
EOCAT
|
||||
want=`$BIN /tmp/cat_nat_eq.cat 2>&1`
|
||||
if $BIN --backend x86_64 --build /tmp/cat_nat_eq.cat /tmp/cat_nat_eq_bin >/dev/null 2>&1 && [ -x /tmp/cat_nat_eq_bin ]
|
||||
then
|
||||
got=`/tmp/cat_nat_eq_bin 2>&1`
|
||||
if [ "$got" = "$want" ]; then
|
||||
check "nat-x86_64-eq" "match" "match"
|
||||
else
|
||||
check "nat-x86_64-eq" "match" "differs"
|
||||
fi
|
||||
else
|
||||
check "nat-x86_64-eq" "skip" "skip"
|
||||
fi
|
||||
rm -f /tmp/cat_nat_eq.cat /tmp/cat_nat_eq_bin
|
||||
|
||||
echo ""
|
||||
echo "$pass passed, $fail failed"
|
||||
[ "$fail" -eq 0 ]
|
||||
Reference in new issue
Block a user