Giter VIP home page Giter VIP logo

flathead's Introduction

Flathead

Flathead is a tiny, portable JavaScript (ECMA-262) interpreter written in C.

Build Status

Flathead's REPL

The interpreter does a direct evaluation of the parse tree—it does not currently build any further IR or perform any optimizations. As a result, it starts up very quickly, and performs well on code that wouldn't benefit much from optimization, and less well on code that would (e.g. loops).

Flathead builds on Linux, OSX and *BSD, on x86, x86_64 and ARM architectures.

Flathead comes with the full EcmaScript runtime (i.e. the Date, Math, Array and other global objects) as well as a console object.

Most of the language is now implemented, you can see the remaining work to be done on the Docket.

Installing

Download or clone the source and run make within.

git clone https://github.com/ndreynolds/flathead.git
cd flathead
make

This creates an executable at bin/flat within the source directory. (You can optionally run make install to copy this to /usr/local/bin/.)

Dependencies

If you received any errors, you may just be missing dependencies.

flex and bison are required to generate the lexer and parser.

The default build depends on GNU Readline (lreadline) for the REPL, and PCRE (lpcre) for the regular expression implementation. They're not required, however, for a minimal build. Run make readline=off regexp=off to compile without them.

If you're still having trouble building, please create an issue.

Running

Once built, you can run bin/flat without arguments to start a REPL:

$ bin/flat
> 2 + 2
4
>

Or with a script as argument:

$ bin/flat say_hello.js
Hello!

View the parse tree with -n:

$ bin/flat -n
> 2 + 2
source list
  expression statement
    expression (binary)
      +
      number (2.000000)
      number (2.000000)
4
>

See all the options with -h:

$ bin/flat -h
Usage: flat [options] [script.js] 

Options:
  -v, --version       print version info
  -h, --help          print this help text
  -i, --interactive   force REPL
  -n, --nodes         print the AST
  -t, --tokens        print tokens

Running the tests

Flathead's test suite can be run against the bin/flat executable, as well as other EcmaScript implementations (assuming you have them installed).

The test runner itself requires Node.js. It locates files with names beginning in test_ and executes them with the configured implementation and options. There are a few Node module dependencies, so you'll need to run npm install before you can run the tests.

The Makefile has a few shortcuts:

make test to run with Flathead's bin/flat executable.
make test-v8 to run using v8.
make test-node to run using node.
make test-sm to run using js (SpiderMonkey).
make test-rhino to run using rhino.

There's also:

make test-grammar to verify parsing and AST formation

The Docket

  • With statement (with)
  • Labels (e.g. loop1: ...; continue loop1;)
  • Automatic Semicolon Insertion
  • Unicode
  • The JSON object (JSON-js can be used as polyfill)
  • URI functions
  • String#replace: replacement function
  • String#split: RegExp separators

flathead's People

Contributors

jpiccari avatar ndreynolds avatar pstef avatar tcort avatar

Watchers

 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.