Driver FixRecommendedSound, Wi-Fi or graphics acting up? Check drivers firstFind missing or outdated drivers fast.Check DriversOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsWindows FixRecommendedWindows errors stealing your time? Find the fix fastScan stability, cleanup and performance issues.Fix Now×
Skip to content
World desk3 min

How a 1 + 1 Assignment Turned Into a C-Based Language Runtime

A simple binary-tree arithmetic exercise became a C-based language runtime, bringing unexpected challenges with environments, closures, memory allocation and garbage collection.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

A binary-tree assignment to evaluate 1 + 1 + 1 led one programmer to build graphLang, a small functional-leaning language runtime in C. The author’s account traces the scope creep through a key idea—treat operators as functions—and the practical problems that followed: representing variables and functions, allocating enough expression nodes, and reclaiming memory.

Why an arithmetic tree became a language project

The author opens the project story with a data-structures exercise: convert an arithmetic expression into a binary tree. Rather than write a special evaluator for each operator, the author reframed operators as functions that take expressions. That made evaluation a matter of applying a function to its arguments, a more general mechanism than separate addition, subtraction, or multiplication cases.

As an Amazon Associate I earn from qualifying purchases.

That shift changed the problem. Once expressions could be evaluated through functions, the runtime needed a way to name values, represent functions as data, and manage the growing graph of expression nodes. The author characterizes the result as a “Graph Reduction engine.”

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

What the runtime needed beyond arithmetic

Variables and environments

Variables require a mapping from names to values. The author added an environment backed by a hash table so expressions could look up bindings during evaluation.

User-defined functions and closures

A C function pointer alone was not enough for a function that should exist within the language’s expression graph and be returned for later evaluation. The article describes representing user-defined functions as closures: graph nodes containing function parameters and bodies. This lets the evaluator treat a function as part of the language’s data rather than only as a built-in C routine.

Why allocation became the next obstacle

The first design used a fixed arena of 1,024 nodes. In the author’s fib(5) example, that was not enough: the author reports that it spawned 13,000 nodes. Expanding one contiguous block could move it and invalidate pointers into the old allocation, so the allocator changed to linked chunks. The author reports that this version used 1.32 MB for fib(5).

The article estimates an expression node at 32 bytes on a 64-bit system before allocator overhead, and says malloc() added 16 bytes on the author’s system. Those are implementation-specific estimates, not universal C layout or allocator constants. With chunk allocation but no collection, the author reports 40 MB for fib(10).

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

How mark-and-sweep changed the memory story

As evaluation created more nodes, allocating in chunks did not by itself reclaim nodes that were no longer needed. The author reports that fib(40) exceeded 12 GB and ended in an out-of-memory crash before garbage collection. The article estimates roughly 1.3 billion nodes and 62.4 GB of cumulative node allocations at 48 bytes per node.

The author then added tracing mark-and-sweep collection, which identifies reachable nodes and reuses unreachable ones. For fib(40), the author reports about 1.7 MB of memory use after the change, with a runtime of six minutes. These are the author’s own measurements; the article does not provide an independently replicated benchmark or enough test details to generalize the figures to other runtimes or machines.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

What the public GraphLang project documents

The public GraphLang repository describes the project as a minimal, dynamically typed, functional-leaning Lisp dialect and VM. Its README documents Lisp-style expressions, variables, first-class functions, closures, let, a REPL, plugins for native functionality, and a tracing mark-and-sweep collector. It also provides make and run examples. These are claims in the project documentation, not the result of an independent code audit.

The original article mentions a lexer and parser, an FFI, a REPL, lambda functions, local variables, tail-call optimization, and a Cheney copying collector among future parts or plans. The later README describes some related capabilities, but the development story alone does not establish that each planned item was completed at the time the article was published. Neither source offers an independent review or replicated performance test.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Best Value

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Windows Errors? Fix Them Before They SpreadFree repair scan
Outdated Drivers Are Slowing You DownFree scan - exact matches

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.