Skip to content

Latest commit

 

History

History
68 lines (49 loc) · 1.19 KB

readme.md

File metadata and controls

68 lines (49 loc) · 1.19 KB

A simple interpreter in Rust.

This project is a simple virtual machine for executing expression, and a tiny programming langage using the Lisp S-expression syntax style that can be parsed and used into the virtual machine.

You can use it like an REPL for the moment (Read–eval–print loop) by typing expression in the terminal :

42
=> 42
(+ 1 2)
=> 3
(+ 1 (* 2 (+ 3 4))) 
=> 15
(& true false)
=> false
(if (== 1 2) 10 20)
=> 20

Strongly typed :

(& true 42)    
Expected `bool` instead of `42` for the 2 arg
> fn(bool, bool) -> bool

Currently support :

  • Integer,
  • Boolean,
  • If Else,
  • and user build in function from the source language

Adding new function/constant/definition from Rust into the virtual machine is easy :

self.add("zero", 0i32);

self.add("true", true);
self.add("false", false);

self.add("void", ());
self.add("bool", Kind::Bool);
self.add("i32", Kind::I32);
self.add("type", Kind::Kind);

self.add("+", |x: i32, y: i32| x + y);
self.add("*", |x: i32, y: i32| x * y);

self.add("&", |x: bool, y: bool| x & y);
self.add("|", |x: bool, y: bool| x | y);

self.add("!", |x: bool| !x);