Git Product home page Git Product logo

hololisp's Introduction

hololisp

codecov Build and Test

hololisp is a lisp-1 bytecode-compiled single-threaded small toy programming language.

Features

hololisp takes inspiration from popular lisp dialects, primarily scheme. It includes bytecode compiler and interpreter, along with tracing garbage collector.

hololisp supports primitive data types:

  • Numbers (internally represented as IEEE754 doubles)
  • Conses
  • Symbols

Language features include:

  • Variables
  • Closures
  • Conditionals
  • Builtin forms (+, =, list and others)
  • User-defined functions
  • C FFI
  • Functions with variadic number of arguments
  • Macros
  • REPL

Compile

make

hololisp is currently tested on arm64 macOS and Linux amd64.

By default, hololisp is compiled in release mode. If you want to compile in debug mode add DEBUG=1 flag to make.

Testing

make test

hololisp testing is divided in two parts: unit testing and system-wide functional testing. Unit testing is done using acutest. System-wide testing is done using small programs located in .sh files found in tests directory.

Code coverage can be collected if non-empty COV flag is passed to make:

make test DEBUG=1 COV=1

Usage

hololisp can be used in three modes: REPL, executing script files, and executing command strings.

To execute script pass its name to the program executable:

hololisp examples/game_of_life.hl

REPL session looks like this:

$ hololisp
hololisp> (define x 100)
x
hololisp> x
100
hololisp> (+ x (* x 100))
10100

To execute command string pass it after -e flag:

$ hololisp -e "(+ 1 2)"
3

Examples

(defmacro (compare pred pivot)
  (list 'lambda (list 'it) (list pred 'it pivot)))

(define (qsort lis)
  (when lis
    (let ((pivot (car lis)) 
          (lis (cdr lis)))
      (append
        (qsort (filter (compare < pivot) lis))
        (list pivot)
        (qsort (filter (compare >= pivot) lis))))))

(print (qsort (list 5 6 2 1 4 5 2 6 3 9 1)))
; (1 1 2 2 3 4 5 5 6 6 9)

Examples can be found in the 'examples' directory.

List of examples:

hololisp's People

Contributors

holodome avatar

Stargazers

Elizarov Dmitry avatar

Watchers

 avatar

hololisp's Issues

Recursive macros

for example,

(defmacro && (expr . rest)
  (if rest
      (list 'if expr (&& rest))
      expr))

(macroexpand (&& 1 2 3))

should evaluate to

(if 1 (if 2 3))

internal error handling with trace dumping

Internal error is caused in situations when assertion is hit that is clear that is caused by compiler failure (for example, wrong constant index).
In this cases abort execution immediately and print information about execution state to file.

NAN-boxing?

In a lot of cases we only need to know the object's type (like in list iteration which happens all the time). We could potentially save time if object type lookup does not require pointer dereference

Runtime error handling

Runtime error is caused by incorrect usage of builtin forms (e.g. wrong type). In this case try to work similar to other languages and print error and call stack.

String hashes?

When comparing symbols we use strcmp, we could save time calling that if use precomputed hashes.

Add line information to bytecode

Bytecode instructions should have file name and line number attached to it. There is no point in storing column number too however.

Sometimes variables are not initialized (possible memory leak)

(lldb) run
Process 12110 launched: '/Users/holod/dev/hololisp/build/hololisp' (arm64)
Undefined variable '+'
eval: error: Unsupported callable type

Undefined variable '*'
eval: error: Unsupported callable type

/Users/holod/dev/hololisp/examples/numbers.lisp:9:1: error: Missing closing paren (eof ecnountered)

^
/Users/holod/dev/hololisp/examples/numbers.lisp:8:9: note: When reading list
        (+ (* 1 123) 0

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.