Allow disassembling continuations and stack frames as well

This commit is contained in:
Konstantin Nazarov 2024-10-06 20:06:01 +01:00
parent a01a4d0574
commit f4660b6bc1
Signed by: knazarov
GPG key ID: 4CFE0A42FA409C22

View file

@ -543,8 +543,22 @@ Result<StackFrame> stdlib_disassemble(const StackFrame& stack) {
auto val = TRY(params.get(0));
if (!val.is<Function>()) return ERROR(TypeMismatch);
auto disassembled = Value(TRY(val.to<Function>()->disassemble()));
Value disassembled;
if (val.is<Function>()) {
disassembled = Value(TRY(val.to<Function>()->disassemble()));
} else if (val.is<Continuation>()) {
auto frame = TRY(val.to<Continuation>()->frame());
auto fun = TRY(frame.fun());
if (!fun.is<Function>()) return ERROR(TypeMismatch);
disassembled = Value(TRY(fun.to<Function>()->disassemble()));
} else if (val.is<StackFrame>()) {
auto fun = TRY(val.to<StackFrame>()->fun());
if (!fun.is<Function>()) return ERROR(TypeMismatch);
disassembled = Value(TRY(fun.to<Function>()->disassemble()));
} else {
return ERROR(TypeMismatch);
}
auto res = TRY(stack.set(0, disassembled));