DEV Community

Atomi J.D.
Atomi J.D.

Posted on

My jdBasic Interpreter Just Got True "Edit and Continue" — In VS Code

We've all been there. You're 15 minutes into a complex debugging session, you've finally reproduced the bug, your app state is perfect, your variables are all set... and you spot the error. It's a one-line fix.

The painful choice: stop the debugger, lose your entire state, re-compile, re-run, and spend another 15 minutes getting back to where you were?

Not anymore.

I'm thrilled to announce that my custom-built interpreter, jdBasic, now supports a true "Edit and Continue" feature, running directly inside Visual Studio Code.

This isn't just "Live Reload" that restarts your app. This is a full p-code (bytecode) hot-swap that preserves your entire application state (call stack, global, and local variables) while the program is paused.

See it in Action

Talk is cheap. Here are three demos of this feature in action during a single, uninterrupted debug session.

1. Changing Function Signatures On-the-Fly

This is the big one. Most hot reload systems balk at changing method signatures. With jdBasic, you can add new parameters to a function, save, and the new signature is live instantly.

Here, I'm paused in the debugger, I change FUNC Add2(a) to FUNC Add(a, b), and then call the new signature from the immediate window.

Live Function Signature Change

2. Defining New Data Structures Live

What if you realize mid-debug that you're missing a data structure? No problem.

In this demo, I'm paused, I write a brand new TYPE Fluppi ... ENDTYPE definition, save the file, and then immediately DIM a new variable of that type and assign values to it.

Live TYPE Definition

3. Mutating State in the Immediate Window

Of course, no debugging experience is complete without an immediate window. While paused, you can execute any jdBasic command. Here, I'm changing the value of a variable C and then printing it with ? (the shortcut for PRINT). This is perfect for testing edge cases or forcing a specific logic path.

Immediate Window State Change

How It Works

This "magic" is possible because jdBasic is an interpreter that compiles source code into an internal p-code representation.

  1. I run my code in VS Code with the debugger (F5).
  2. When I hit a breakpoint, the program pauses.
  3. I can edit any of my .jdb source files and hit Save (Ctrl+S).
  4. The jdBasic interpreter detects the save, recompiles the entire source file into a fresh block of p-code, and atomically swaps the old p-code with the new one.
  5. It then intelligently remaps the current execution pointer to the equivalent instruction in the new p-code.
  6. I press "Continue" (F10), and the new, corrected code is executed.

Best of all, this fully supports VS Code's "Jump to Cursor" feature. If I make a huge change and the old execution pointer doesn't make sense, I can just right-click any line in my program, select "Jump to Cursor," and the interpreter will resume execution from that exact spot.

This has been a game-changer for my own productivity.

You can explore the interpreter's source code, dive into the documentation, and see more examples over at the official GitHub repository: https://github.com/AtomiJD/jdBasic

Top comments (0)