Skip to content

Commit

Permalink
fix: ensure new frames are floating when called from a floating frame…
Browse files Browse the repository at this point in the history
… and set frame of a deferred function as floating when panicking
  • Loading branch information
jacopodl committed Aug 21, 2024
1 parent a6aa114 commit cfcda42
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions argon/vm/fiber.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@
//
// Licensed under the Apache License v2.0

#include <argon/vm/fiber.h>
#include <argon/vm/runtime.h>

#include <argon/vm/datatype/nil.h>
#include <argon/vm/fiber.h>

using namespace argon::vm;
using namespace argon::vm::datatype;
Expand Down Expand Up @@ -62,6 +64,9 @@ Fiber *argon::vm::FiberNew(Context *context, unsigned int stack_space) {
Frame *argon::vm::FrameNew(Fiber *fiber, Code *code, Namespace *globals, bool floating) {
auto slots = code->stack_sz + code->sstack_sz + code->locals_sz;

if (!floating && fiber->frame != nullptr && fiber->frame->fiber_id == 0)
floating = true;

auto *frame = fiber->FrameAlloc(slots, floating);
if (frame == nullptr)
return nullptr;
Expand Down Expand Up @@ -120,7 +125,9 @@ Frame *argon::vm::FrameNew(Fiber *fiber, Function *func, ArObject **argv, ArSize
if (func->IsNative())
return FrameWrapFnNew(fiber, func, argv, argc, mode);

if ((frame = FrameNew(fiber, func->code, func->gns, func->IsGenerator())) == nullptr)
auto floating = func->IsGenerator() || IsPanicking();

if ((frame = FrameNew(fiber, func->code, func->gns, floating)) == nullptr)
return nullptr;

// Push currying args
Expand Down

0 comments on commit cfcda42

Please sign in to comment.