(enjoyable: fib-rec [n Int] Int
(if (
intro
Snabl projects targets to put in power embedded Disclose interpreter in C++.
motivation
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++.
form
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.
language
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.
- TIMTOWTDI
- Parens are for calls, vectors utilize brackets
- The entirety is one procedure
let*
is defult
web content online
The codebase is impending 2
kloc. Currently verifying and tweaking the kind to toughen efficiency in conserving with preliminary profiling. Error checking still leaves loads to need for.
setup
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
bindings
let
will likely be old to bind values to identifiers internal a scope.
(let [foo 35 bar (+ foo 7)] bar)
42
efficiency
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 233
ms on the the same machine.
(bench 100 (fib-rec 20))
1037
Next tail recursive, Python3 takes 105
ms 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))
397
toughen
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.