r/Compilers • • 5d ago

I got tired of Python-wrapped VMs, so I rewrote my language’s entire frontend in Pure C. Here’s what happened in FoxVC v2.0 & the 0.7.1 “Titan” update.

Hey r/Compilers !

 A while back, I started building FoxVC—a lightweight, zero-dependency scripting language and bytecode virtual machine designed around 25 deterministic keywords
 (act, emit, pick, alt, spin, pulse, etc.).

 Like a lot of hobby language projects, it originally started with a classic architecture: a Python frontend (lexer, AST parser, bytecode compiler) that called
 into a fast C VM (foxvm.so) via ctypes.
 It was fun, it worked, but eventually, I hit what I call the "3-language duplication trap":
 1. You write a feature in Python.
 2. You have to sync it with your C VM.
 3. Then you want a WebAssembly browser playground, so you end up maintaining a third JavaScript parser that slowly drifts out of sync.
 4. Worst of all: cold-start latency sucked. Spawning Python just to parse a 20-line .fox script took ~200ms before the C VM even touched the first bytecode opcode.

 Over the last few weeks, I pushed two massive updates—v2.0.0 (Engine 0.7.0) and today’s v0.7.1 “Titan” update—to completely overhaul the engine.

0 Upvotes

6 comments sorted by

5

u/good_name_0 5d ago

Is it ai generated like your post is?

0

u/Hopeful-Ad-1665 21h ago

The post formatting was cleaned up with AI, yeah, not gonna lie. But the C code, benchmarks, and bugs are all real—just spent today fixing a stack overflow in the C parser and cleaning up the Windows build.

3

u/Key_Detail15 5d ago edited 5d ago

Worst of all: cold-start latency sucked. Spawning Python just to parse a 20-line .fox script took ~200ms before the C VM even touched the first bytecode opcode.

How often do you have to cold-start Python? Anyway my tests show CPython has start-up overhead of 50ms on Windows and 30ms on WSL. Maybe there is another reason for that 200ms. (node.js is genuinely poor at some 500ms latency.)

a lightweight, zero-dependency scripting language

If it needs Python then it's not quite zero! Unless you assume that a Python implementation exists (it doesn't on Windows).

You write a feature in Python.
You have to sync it with your C VM.

I've had worse:

  • I had a compiler/interpreter for 'B' (say) written in my self-hosted systems language 'A'
  • At one point I thought it'd be a good idea to write the compiler for A in B (so a circular dependency)

This sort of worked, but I got all sorts of horrendous 'phase' errors if I wanted to change details such as inserting a new bytecode. Changes were made to A's sources, compiled with the B interpreter whose binary still had the old codes..

In the end there was a 20-point step-by-step list to get everything updated, involving the old versions, new versions, and mixed versions.

Eventually the idea was dropped.

2

u/AustinVelonaut 5d ago

That sounds like an interesting setup -- I know I've forgotten a couple of times to do the triple-compile equivalency to check mine, before. Imagine trying to make a change to a 128-language quine oroboros, though!

0

u/Hopeful-Ad-1665 21h ago

Haha yeah, keeping two pieces in sync is already annoying enough—triple-compile checks or a 128-language chain sounds like a nightmare. Putting the parser, VM,
  and WASM build on one shared C header so opcode numbers can't drift apart already saved me a ton of headaches.

0

u/Hopeful-Ad-1665 21h ago

Good catch on all three—you were actually right:
 
  1. The ~200ms latency: You're right, bare Python starts in ~26 ms on my machine too. The extra ~200–350 ms was our old Python CLI importing all the stdlib
  modules (sqlite3, http, ctypes, etc.) on every run before touching a single bytecode opcode. Switching the parser to pure C dropped cold-start on the math
  benchmark from ~377 ms avg down to ~4–6 ms.
  2. Zero-dependency on Windows: Also fair. Even after rewriting the engine in C, I checked my repo and realized install.bat was still checking for Python and
  pointing to the old Python CLI, and my C transpiler was emitting GCC-only nested functions inside main() that broke on Clang/MSVC. Just rewrote install.bat to
  compile foxvc.exe straight with gcc/clang/cl and moved generated functions to standard top-level C99.
  3. Syncing opcodes / phase errors: That exact pain is why I dropped the Python frontend. I even caught the new C VM and WASM file still hardcoding raw opcode
  numbers—just moved all of them onto one shared header (fox_core.h) so changing or adding an opcode updates everything in one compile.