All Projects → eudoxia0 → Interim

eudoxia0 / Interim

Licence: gpl-3.0
Low-level Lisp with compile-time memory management

Programming Languages

lisp
113 projects

Labels

Projects that are alternatives of or similar to Interim

Veriloggen
Veriloggen: A Mixed-Paradigm Hardware Construction Framework
Stars: ✭ 182 (-10.78%)
Mutual labels:  compiler
Lhc
The LLVM LHC Haskell Optimization System
Stars: ✭ 188 (-7.84%)
Mutual labels:  compiler
Bridge
♠️ C# to JavaScript compiler. Write modern mobile and web apps in C#. Run anywhere with Bridge.NET.
Stars: ✭ 2,216 (+986.27%)
Mutual labels:  compiler
Prototype
(deprecated) The journey continues at ASNEXT: https://github.com/AssemblyScript/assemblyscript
Stars: ✭ 2,114 (+936.27%)
Mutual labels:  compiler
Faerie
Magical ELF and Mach-o object file writer backend
Stars: ✭ 187 (-8.33%)
Mutual labels:  compiler
Ape
Ape Programming Language
Stars: ✭ 195 (-4.41%)
Mutual labels:  compiler
Philip2
An Elm to OCaml compiler
Stars: ✭ 182 (-10.78%)
Mutual labels:  compiler
Nxdk
The cross-platform, open-source SDK to develop for original Xbox: *new* xdk
Stars: ✭ 200 (-1.96%)
Mutual labels:  compiler
El Compilador
An SSA-based compiler for Emacs Lisp
Stars: ✭ 187 (-8.33%)
Mutual labels:  compiler
Tengo
A fast script language for Go
Stars: ✭ 2,528 (+1139.22%)
Mutual labels:  compiler
Mlkit
Standard ML Compiler and Toolkit
Stars: ✭ 183 (-10.29%)
Mutual labels:  compiler
Hybridizer Basic Samples
Examples of C# code compiled to GPU by hybridizer
Stars: ✭ 186 (-8.82%)
Mutual labels:  compiler
Fast
Find in AST - Search and refactor code directly in Abstract Syntax Tree as you do with grep for strings
Stars: ✭ 194 (-4.9%)
Mutual labels:  compiler
Appfairy
A CLI tool to Migrate a Webflow project into a React app
Stars: ✭ 183 (-10.29%)
Mutual labels:  compiler
Cub
The Cub Programming Language
Stars: ✭ 198 (-2.94%)
Mutual labels:  compiler
Tampio
Tampio: An object-oriented programming language made to resemble Finnish
Stars: ✭ 181 (-11.27%)
Mutual labels:  compiler
Splash
Simple Programming LAnguage for SHortcuts
Stars: ✭ 192 (-5.88%)
Mutual labels:  compiler
Binaryen.js
A buildbot for binaryen.js, a port of Binaryen to the Web, with TypeScript support.
Stars: ✭ 201 (-1.47%)
Mutual labels:  compiler
Xdpw
XD Pascal: A small embeddable self-hosting Pascal compiler for Windows. Supports Go-style methods and interfaces
Stars: ✭ 199 (-2.45%)
Mutual labels:  compiler
He Transformer
nGraph-HE: Deep learning with Homomorphic Encryption (HE) through Intel nGraph
Stars: ✭ 195 (-4.41%)
Mutual labels:  compiler

Interim

Build Status

Interim is a statically-typed, low-level dialect of Lisp featuring compile-time, GC-free memory management.

Interim is a technology demonstrator for compile-time memory management using regions. As of 2018, the only major language with compile-time memory management is Rust, which is notoriously tough to learn. Interim was built to prove that sound, GC-free, compile-time memory management can be both simple to implement and easy to learn and use.

Overview of Regions

Memory safety is achieved by preventing three classes of errors:

  • NULL pointers
  • Double free()
  • Use after free() (dangling pointers)

Preventing NULL pointers is easy: we use an option type (called Maybe in Haskell). In the case of Interim, we have a special pointer type called nullable which represents a pointer which is potentially NULL. The case construct can be used to extract a never-NULL pointer in a safe way.

Preventing double free() and use after free() errors is harder, and this is where regions come in.

Consider this code:

(letregion rho
  (let ((p (allocate rho 10)))
    (letregion rho'
      (let ((p' (allocate rho' 12)))
        nil))))

What we're doing here is:

  1. Defining a region rho. Regions are both lexical objects and run-time values.

  2. Defining a variable p, whose initial value is the result of allocating the number 10 in the region rho.

    An allocate call takes a value of type T and a region indentifier, allocates enough memory in the region to hold that value, and returns a pointer to it. The result pointer has the type (nullable T R), where T is the type of the value we're allocating and R is the region identifier.

  3. Defining a new region rho'.

  4. Defining a new variable p', whose initial value is (allocate rho' 12), that is, the result of allocating the value 12 in the region rho'.

  5. Finally, return nil.

Now notice what happens if we try to store p' in p:

(letregion rho
  (let ((p (allocate rho 10)))
    (letregion rho'
      (let ((p' (allocate rho' 12)))
        (<- p p')))))

The compiler will fail with

Cannot assign to variable 'p': the type of the variable is (nullable i32 rho),
while the type of the expression is (nullable i32 rho')

This is the key to preventing dangling pointer errors: pointers are tagged with the region they belong to. A pointer cannot escape its lifetime, to a higher-up region or to a global variable, because the types won't match.

Double free() errors are prevented through a straightforward feature of regions: there is no way to do a manual free(), and everything in a region is freed automatically when exiting the region's body.

Examples

For more examples, look in the examples/ directory.

Hello World

(defun main () i32
  (println "Hello, world!")
  0)

Fibonacci

(defun fib ((n i32)) i32
  (if (< n 2)
      n
      (+ (fib (- n 1))
         (fib (- n 2)))))

(defun main () i32
  (print "fib(30) = ")
  (println (fib 30))
  0)

Output:

fib(30) = 832040

Regions

(defun main () i32
  (letregion rho
    (let ((p (allocate rho 10)))
      (case p
        ((not-null p')
         (print "Allocated successfully! Value: ")
         (println (load p'))
         0)
        (null
         (println "Out of memory!")
         -1)))))

Output:

Allocated successfully! Value: 10

Building

You need MLton, git and make to build Interim. On Ubuntu:

$ sudo apt-get install mlton git make

Then:

$ make interim

After building, try

$ make examples

Dependencies

The only dependency is Parsimony, a parser combinator library.

Design

Being a technology demonstrator, Interim lacks many features of real languages: modules, macros, higher-order functions, and higher-order types are not implemented since the focus is on region-based memory management.

As the name implies, Interim is a stepping stone or proof of concept for a larger, more sophisticated language.

Bibliography

License

Copyright 2018 Fernando Borretti.

Licensed under the GPLv3 license. See the COPYING file for details.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].