Rewrite with working async

This commit is contained in:
2026-10-16 08:00:06 +00:00
parent d0c2f291e9
commit 1e4647347f
36 changed files with 5106 additions and 654 deletions
+21 -1
View File
@@ -126,6 +126,22 @@ class OpDef(NamedTuple):
temporary: bool # written as lowercase `def()`: a compiler-only opcode
# Opcodes that this compiler adds. QuickJS never emits them, so they come after
# every real opcode and `short_opcode_info` never gives them for a byte of
# bytecode. Only the transforms emit them.
EXTRA_OPS = [
# [obj, value] -> [obj]: like `define_field`, but the field is the location
# that `value` was read from, not a copy of it (see transform/closure.rs)
OpDef("define_field_ref", 5, 2, 1, "atom", False),
# [] -> []: like `close_loc`, for a capture: the binding that capture `i` shares gets a
# new location, with the current value (see transform/async.rs)
OpDef("close_var_ref", 3, 0, 0, "var_ref", False),
# [obj] -> []: field `x` of `obj`, which shares a location, gets a new location, with
# the current value. What `close_var_ref` lowers to (see transform/closure.rs)
OpDef("close_field", 5, 1, 0, "atom", False),
]
def parse_fmt_list(text: str) -> list[str]:
"""The `FMT(name)` list, in order."""
out = []
@@ -284,6 +300,8 @@ def gen_opcodes(text: str, tag: str) -> str:
# no short-opcode shift, unlike the C `short_opcode_info` macro whose table
# still holds them.
real = [o for o in ops if not o.temporary]
real_count = len(real)
real += EXTRA_OPS
s = [header(tag, "quickjs-opcode.h")]
@@ -351,8 +369,10 @@ def gen_opcodes(text: str, tag: str) -> str:
"///\n"
"/// The table already excludes the compiler's temporary opcodes, so the\n"
"/// byte indexes it directly; there is no short-opcode shift to apply.\n"
"/// The opcodes that this compiler adds are not in bytecode, so they\n"
"/// are never given.\n"
"pub fn short_opcode_info(op: u8) -> Option<&'static OpInfo> {\n"
" OPCODE_INFO.get(op as usize)\n"
f" OPCODE_INFO[..{real_count}].get(op as usize)\n"
"}\n"
)
return "".join(s)