Skip to content

Bug: Chapter 24.3 - REPL issue #1207

Description

@LeslieMurphy

At the end of Chapter 24.3, clox is once again running. However, I think Chapter 24 introduced a bug in how REPL is being handled.

If I run

{var a = 123; print a;}

it works as expected and prints 123.

But if I run it again in the same REPL session it does not print anything.

The issue is that we push another copy of the implicit function onto the vm stack, thus throwing off what the compiler set as the slot for the variable.

My fix was to add:

resetStack();

in the interpret() function in vm.c just before we push the SCRIPT wrapper function.

Is that the correct way to fix this bug? Perhaps later in the book the bug gets fixed in some other manner; I have not gotten that far yet.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions