GitXplorerGitXplorer
i

half-and-half

public
4 stars
1 forks
2 issues

Commits

List of commits on branch master.
Unverified
164370c8f850e3e9c367c2a0d89c32fc6e9e6295

Merge pull request #3 from michaelficarra/patch-2

iint3 committed 12 years ago
Unverified
6e74cf709a54cab7254cfd7c2c5578ccd908d7f3

fix option parsing for `cfg` option

mmichaelficarra committed 12 years ago
Unverified
3fd76756044e870c320ff12597d3a1a399795bbd

Merge pull request #2 from michaelficarra/patch-1

iint3 committed 12 years ago
Unverified
507548e647e8066a62417535cda21ba81c0dbfa6

Javascript -> JavaScript

mmichaelficarra committed 12 years ago
Unverified
26e4f13b7327b8f58e63fc413acac359146de3f7

Add disclaimer of unreadiness.

iint3 committed 12 years ago
Unverified
a15d19682a7de0267aaf7e145dc42400df16362d

Conditional jump test should add to liveness. Fixes #1.

iint3 committed 12 years ago

README

The README file for this repository.

half-and-half

A simple partial evaluator for JavaScript.

Disclaimer: This is currently a hackish prototype. It only supports a subset of JavaScript syntax, and only deals with code written in the global environment.

Setup & Usage

npm install
./half-and-half <filename>

Examples

The following example is an if statement in a while loop that emulates gotos using a label variable. The underlying control flow can be written much more simply as an if-else statement, though, and half-and-half is able to figure that out:

./half-and-half examples/while_if.js

More interestingly, here is a brainfuck program that does the equivalent of cat. (It reads from a file named 'input' because node doesn't allow synchronous reading from stdin, and async code would make the interpreter harder to specialize.)

echo "123450" > input
./half-and-half examples/brainfuck.js

The brainfuck code is assigned to a program variable at the top of brainfuck.js. There is also a commented-out "hello world" program in the same file, though I think it makes a less interesting example since no control flow statements are produced in the specialized code.

Debugging

The control-flow graph of the compiled source can be visualized using GraphViz.

coffee peval.coffee --cfg <filename> | dot -Tpdf -o dot.pdf

You can also see the result of the desugaring + basic block conversion process via

coffee desugar.coffee <filename>