Permalink
Find file
Fetching contributors…
Cannot retrieve contributors at this time
158 lines (130 sloc) 3.46 KB
## Syntax:
- loop convenience macros / libraries / special "syntax",
macros
- forward declarations
- let (macro)
- better object prototypes / inheritence ?
- ???
======================================
Layers:
Each phase deals with js / json, but can also produce lisp-ish syntax
1. Program
((lambda () (+ x x)))
equivalent in js: (function() { x + x })()
2. jison Parser spits out representation in json:
{
type: 'list',
contents: [
{
type: 'list',
contents: [
{ type: 'id', contents: 'lambda' },
{ type: 'list', contents: [] },
{
type: 'list',
contents: [
{ type: 'id', contents: '+'},
{ type: 'id', contents: 'x'},
{ type: 'id', contents: 'x'}
]
}
]
}
]
}
equivalent syntax in loop:
(list
(list
(id lambda)
(list)
(list
(id +)
(id x)
(id x))))
3. Syntax tree gets "eval'ed" from pure syntax to have "meaning":g
(notice that (lambda () ...) is actually still considered a function call)
{
type: funcall,
function: {
type: 'funcall',
function: { type: 'id', contents: 'lambda' },
arguments: [
{
type: 'list',
arguments: []
}
{
type: 'list',
arguments: [
{
type: 'funcall',
function: { type: 'id', contents: '+' },
arguments: [
{ type: 'id', contents: 'x' },
{ type: 'id', contents: 'x' }
]
}
]
}
]
},
arguments: { type: 'list', contents: [] },
}
(funcall
(funcall
(id 'lambda')
(list)
(list
(funcall
(id +)
((id x)
(id x)))))
())
Equivalent:
(funcall
'lambda
(list)
(list
'funcall
'+
(list
(id x)
(id x))))
4. Syntax tree undergoes transformations to get it into an equivalent uglify syntax:
(notice that built in statements like + which were previously considered functions are here converted to binary, unary, etc for js)
["toplevel",
[
["stat",
["call",
["function", null, [],
[["stat",
["binary","+",
["name","x"],
["name","x"]]]]],
[]]]]]
- raw javascript (pretty printed, through uglify)
- uglify javascript (compressed)
## Loop principles:
base translator:
- write javascript in scheme/lisp syntax
- no differences from regular javascript
- except macros!
Loop additional packages:
- cleanup ugly parts of javascript
- prototypes as first class principle - use real js prototypes
Other things that may be interesting:
* translating sync => async
* adding types:
(var square
(lambda ((number x) (number x))
(* x x)))
* js => loop compiler
* translating recursion => iteration
* call/cc
## TODO:
* Support for strings with single quotes
* Support all keywords
* Utf-8?
* Use function keyword as well as lambda
* use define as well as var
* better support for + (see http://dreaminginjavascript.wordpress.com/2008/07/04/28/ + UNARY_OPERATORS)