Repeat HN: Snabl – embedded Disclose in C++

(fun: fib-rec [n Int] Int (if (< n 2) n (+ (fib-rec (dec n)) (fib-rec (dec n 2))))) (fib-rec 10) 55 intro Snabl projects aims to implement a practical embedded Lisp interpreter in C++. motivation I like command lines, almost regardless of type of application. And once you have a command line, some flavor of…

Repeat HN: Snabl – embedded Disclose in C++

Lisp Mascot

  (enjoyable: fib-rec [n Int] Int
    (if (


Snabl projects targets to put in power embedded Disclose interpreter in C++.


I admire declare traces, nearly regardless of model of utility. And even as you maintain got gotten a declare line, some taste of scripting is suitable all the procedure through the corner. So that it is possible you’ll per chance presumably as correctly draw for it by utilizing a right foundation. Which formulation that it is a long way ideal to care for a gradual skill and dwell away from paying upfront. This challenge is supposed to simplify implementing that draw; by offering a flexible, modular framework for implementing interpreted languages in C++.


The VM is register primarily primarily based completely with sequential allocation and runs 64-bit bytecode. The review loop is implemented using computed goto for efficiency causes, that formulation that the trouble of on hand operations is mounted. States and frames are slab allocated, reference counted and handed as raw pointers. Kinds and values are designed to be (cheaply) handed by cost. The reader is implemented using recursive descent and designed to be easy to customise/prolong.


The tip of the iceberg is a custom Disclose that desires to be as pragmatic as Basic Disclose while leaving the cruft within the aid of.

  • Parens are for calls, vectors utilize brackets
  • The entirety is one procedure
  • let* is defult

web content online

The codebase is impending 2kloc. Currently verifying and tweaking the kind to toughen efficiency in conserving with preliminary profiling. Error checking still leaves loads to need for.


Building the challenge requires a C++17-compiler and CMake, the next shell spell builds and starts the REPL:

$ cd snabl
$ mkdir invent
$ cd invent
$ cmake ..
$ invent
$ ./snabl


let will likely be old to bind values to identifiers internal a scope.

  (let [foo 35 bar (+ foo 7)] bar)



bench returns elapsed time in milliseconds for specified series of repetitions. The present efficiency focal level is figuring out and fusing bytecode patterns.

First up is classic recursive Fibonacci, Python3 takes 233ms on the the same machine.

  (bench 100 (fib-rec 20))


Next tail recursive, Python3 takes 105ms on the the same machine.
Snabl detects and fuses tail calls automagically at assemble time.

  (enjoyable: fib-tail [n Int a Int b Int] Int
    (if (z? n) a (if (one? n) b (fib-tail (dec n) b (+ a b)))))

  (bench 10000 (fib-tail 70 0 1))



When you happen to maintain to toughen Snabl and reduction me utilize more time and vitality on evolving the challenge, please take into myth a donation in Bitcoin 3Qv3GdBCabkAustonEoEv63mVXMS8htiB5 or Ether 0x5BD559b709800731324e32eC512d786987DAdb0F.

coder/mentor for rent

I am on the 2d on hand for rent.
Distant or relocation internal Europe.
Ship a message to codr7 at protonmail and I will receive reduction to you asap.

Read More

Charlie Layers

Charlie Layers

Fill your life with experiences so you always have a great story to tellBio: About: