Giter Club home page Giter Club logo

asmlisp's Introduction

ASMLisp

ASMLisp is an experimental programming language created in order to explore the power of functional programming within assembly.

Motivation

  • LISP and assembly languages have a similar reverse Polish notation syntax.
  • LISP symbols and CPU registers are both typeless.
  • Functional closures in imperative languages like JavaScript are extremely powerful.
  • Straightforward implementation: inline all function calls.

Examples

There are many assembler macro systems which allow defining macro instructions, for example, incrementing a register. In ASMLisp, this can be achieved with:

(define increment (λ register
    (addi register register 1)))

ASMLisp takes this principle a step further by allowing code to be passed as data. This leads to more powerful functions like the following:

(define doTwice (λ do
    (do)
    (do)))

doTwice then allows creating an incrementTwice function as the following:

(define incrementTwice (λ register
    (doTwice (λ
        (increment register)))))

Non-Local Jumps

Non-local jumps can be used for exception handling. Consider the use-case of checking if the index is out of bounds before an array access. In this example, out-of-bounds-handler-label is defined in the outer scope and passed in to handle an exception:

(define safe-array-access (\ load-into array length index out-of-bounds-handler-label
    (jlt length index out-of-bounds-handler-label)
    (define address load-into)
    (add address array index)
    (lw load-into address)))

Grammar

    <program> ::= <definition>*
<instruction> ::= "(" (<definition> | <label> | <call>) ")"
 <definition> ::= "define" <identifier> <argument>
      <label> ::= "label" <identifier>
       <call> ::= <identifier> <argument>*
   <argument> ::= <identifier> | <lambda> | <immediate>
     <lambda> ::= "(" ("lambda" | "λ") <identifier>* <instruction>* ")"
 <identifier> ::= /[a-zA-Z]*/
  <immediate> ::= /[1-9]\d*/

Semantic Rules

  • Global scope consistes of all top-level definitions in any order.
  • Local scope consists of all the define statements executed within the block of instructions (or within its parent's local scope). at up to the instruction in question.
  • There must be a main lambda in global scope with no arguments.
  • An identifier must be in local or global scope before it can be resolved.

asmlisp's People

Contributors

schreiberbrett avatar

Stargazers

 avatar

Watchers

James Cloos avatar  avatar

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.