Permalink
Browse files

regenerate compiler

  • Loading branch information...
1 parent 9783895 commit 960b4160d092e7a341ae3b89a091f70641a3e94b @jlongster committed Feb 20, 2012
Showing with 304 additions and 125 deletions.
  1. +16 −0 backends/js.js
  2. +58 −3 compiler.js
  3. +27 −5 compiler.ol
  4. +46 −0 docs/ref.textile
  5. +17 −1 grammar.js
  6. +17 −1 parser.js
  7. +7 −0 r.ol
  8. +4 −3 test.ol
  9. +112 −112 tests/compile.ol
View
@@ -33,6 +33,15 @@ function for_dash_each(func, lst) {
}
}
+function fold(func, acc, lst) {
+ if(null_p_(lst)) {
+ return acc;
+ }
+ else {
+ return fold(func, func(car(lst), acc), cdr(lst));
+ }
+}
+
function make_dash_vector(i) {
return new Array(i);
}
@@ -53,6 +62,10 @@ function vector_dash_for_dash_each(func, vec) {
}
}
+function vector_dash_length(vec) {
+ return vec.length;
+}
+
function display(msg) {
__util.print(msg);
}
@@ -383,6 +396,9 @@ function _dash__gt_string(obj) {
}
return '{' + res.join(', ') + '}';
}
+ else if(null_p_(obj)) {
+ return '()';
+ }
}
function list_dash_append(lst1, lst2) {
View
@@ -504,8 +504,55 @@ return (number_p_(x) || string_p_(x) || boolean_p_(x) || null_p_(x));
var application_p_ = (function(form){
return (list_p_(form) && not(expander_p_(car(form))));
});
-var ref = (function(obj,name){
-return object_dash_ref(obj,symbol_dash__gt_string(name));
+var ref = (function(obj,val){
+return (function() {if(list_p_(obj)) {return ((function() {var walk = (function(lst,i){
+return (function() {if(null_p_(lst)) {return ((function() {return false;
+}))();
+} else {return (function() {if(eq_p_(i,0)) {return ((function() {return car(lst);
+}))();
+} else {return ((function() {return walk(cdr(lst,(i - 1)));
+}))();
+}})()
+;
+}})()
+;
+});
+return walk(obj,val);
+}))();
+} else {return (function() {if(vector_p_(obj)) {return ((function() {return vector_dash_ref(obj,val);
+}))();
+} else {return (function() {if(dict_p_(obj)) {return ((function() {return object_dash_ref(obj,symbol_dash__gt_string(val));
+}))();
+} else {return false;
+}})()
+;
+}})()
+;
+}})()
+;
+});
+var slice = (function(obj,i){
+return (function() {if(list_p_(obj)) {return ((function() {var walk = (function(lst,i){
+return (function() {if(null_p_(lst)) {return ((function() {return false;
+}))();
+} else {return (function() {if(eq_p_(i,0)) {return ((function() {return lst;
+}))();
+} else {return ((function() {return walk(cdr(lst,(i - 1)));
+}))();
+}})()
+;
+}})()
+;
+});
+return walk(obj,i);
+}))();
+} else {return (function() {if(vector_p_(obj)) {return ((function() {return obj.slice(i);
+}))();
+} else {return false;
+}})()
+;
+}})()
+;
});
var put_excl_ = vector_dash_set_excl_;
var opt = (function(arg,def){
@@ -564,13 +611,21 @@ return pad(i);
return pretty(item,(i + 1));
}),childr);
return disp(")");
-}))(car(obj),cdr(obj),(space(obj) > 30));
+}))(car(obj,0),cdr(obj,1),(space(obj) > 30));
+}))();
+} else {return (function() {if(vector_p_(obj)) {return ((function() {return disp(_dash__gt_string(obj));
+}))();
+} else {return (function() {if(dict_p_(obj)) {return ((function() {return disp(_dash__gt_string(obj));
}))();
} else {return false;
}})()
;
}})()
;
+}})()
+;
+}})()
+;
}))((function() {if(null_p_(i)) {return 1;
} else {return car(i);
}})()
View
@@ -21,8 +21,28 @@
(and (list? form)
(not (expander? (car form)))))
-(define (ref obj name)
- (object-ref obj (symbol->string name)))
+(define (ref obj val)
+ (cond
+ ((list? obj)
+ (define (walk lst i)
+ (cond
+ ((null? lst) #f)
+ ((eq? i 0) (car lst))
+ (else (walk (cdr lst (- i 1))))))
+ (walk obj val))
+ ((vector? obj) (vector-ref obj val))
+ ((dict? obj) (object-ref obj (symbol->string val)))))
+
+(define (slice obj i)
+ (cond
+ ((list? obj)
+ (define (walk lst i)
+ (cond
+ ((null? lst) #f)
+ ((eq? i 0) lst)
+ (else (walk (cdr lst (- i 1))))))
+ (walk obj i))
+ ((vector? obj) (obj.slice i))))
(define put! vector-set!)
@@ -63,8 +83,8 @@
((or (symbol? obj)
(literal? obj)) (disp (->string obj)))
((list? obj)
- (let ((node (car obj))
- (childr (cdr obj))
+ (let ((node (car obj 0))
+ (childr (cdr obj 1))
(sp (> (space obj) 30)))
(disp "(")
(pretty node (+ i 1))
@@ -75,7 +95,9 @@
(disp " "))
(pretty item (+ i 1)))
childr)
- (disp ")")))))
+ (disp ")")))
+ ((vector? obj) (disp (->string obj)))
+ ((dict? obj) (disp (->string obj)))))
_str)
View
@@ -0,0 +1,46 @@
+---
+layout: page
+title: Reference
+id: reference
+---
+
+h2. Types
+
+* "@(number? <val>)@":#number_p
+* "@(string? <val>)@":#string_p
+* "@(boolean? <val>)@":#boolean_p
+* "@(null? <val>)@":#null_p
+* "@(list? <val>)@":#list_p
+* "@(vector? <val>)@":vector_p
+* "@(dict? <val>)@":#dict_p
+
+h2. Functions and Variables
+
+* "@(lambda (<arg> ...) <expr> ...)@":#lambda
+* "@(define <var> <expr>)@":#define
+* "@(define (<var> <arg> ...) <expr> ...)@":#define
+* "@(let ((<var> <expr>) ...) <body> ...)@":#let
+
+h2. Conditionals
+
+* "@(if <test> <tru> <fal>)@":#if
+* "@(cond (<test> <body> ...) ...)@":#cond
+* "@(case <expr> ([<val> | (<val> ...)] <body> ...) ...)@":#case
+
+h2. Data Structures
+
+h3. Strings
+
+* "@(str <val> ...)@":#str
+* "@(ref <seq> <i>)@":#ref
+* "@(put! <seq> <val>)@":#put_excl
+* "@(slice <seq> <start> & <end>)@":#slice
+* "@(splice <seq> <seq-from> <start> & <end>)@":#splice
+
+h3. Vectors/Lists/Dicts
+
+* @(vector/list/dict <val> ...)@
+* "@(ref <seq> <i>)@":#ref
+* "@(put! <seq> <val>)@":#put_excl
+* "@(slice <seq> <start> & <end>)@":#slice
+* "@(splice <seq> <seq-from> <start> & <end>)@":#splice
View
@@ -33,6 +33,15 @@ function for_dash_each(func, lst) {
}
}
+function fold(func, acc, lst) {
+ if(null_p_(lst)) {
+ return acc;
+ }
+ else {
+ return fold(func, func(car(lst), acc), cdr(lst));
+ }
+}
+
function make_dash_vector(i) {
return new Array(i);
}
@@ -53,6 +62,10 @@ function vector_dash_for_dash_each(func, vec) {
}
}
+function vector_dash_length(vec) {
+ return vec.length;
+}
+
function display(msg) {
__util.print(msg);
}
@@ -333,7 +346,7 @@ function boolean_p_(obj) {
}
function list_p_(obj) {
- return obj && obj.list !== undefined;
+ return !!obj && obj.list !== undefined;
}
function vector_p_(obj) {
@@ -383,6 +396,9 @@ function _dash__gt_string(obj) {
}
return '{' + res.join(', ') + '}';
}
+ else if(null_p_(obj)) {
+ return '()';
+ }
}
function list_dash_append(lst1, lst2) {
View
@@ -33,6 +33,15 @@ function for_dash_each(func, lst) {
}
}
+function fold(func, acc, lst) {
+ if(null_p_(lst)) {
+ return acc;
+ }
+ else {
+ return fold(func, func(car(lst), acc), cdr(lst));
+ }
+}
+
function make_dash_vector(i) {
return new Array(i);
}
@@ -53,6 +62,10 @@ function vector_dash_for_dash_each(func, vec) {
}
}
+function vector_dash_length(vec) {
+ return vec.length;
+}
+
function display(msg) {
__util.print(msg);
}
@@ -333,7 +346,7 @@ function boolean_p_(obj) {
}
function list_p_(obj) {
- return obj && obj.list !== undefined;
+ return !!obj && obj.list !== undefined;
}
function vector_p_(obj) {
@@ -383,6 +396,9 @@ function _dash__gt_string(obj) {
}
return '{' + res.join(', ') + '}';
}
+ else if(null_p_(obj)) {
+ return '()';
+ }
}
function list_dash_append(lst1, lst2) {
View
@@ -0,0 +1,7 @@
+
+(define (type obj)
+ )
+
+(define (number? obj)
+ (eq? (type obj) 'number))
+
View
@@ -38,8 +38,9 @@
;;(gen.write-runtime "js")
(compiler.set-macro-generator gen)
-
+
(let ((f (expand-nth (read src) 1000)))
- ;;(compiler.pretty f)
+ ;;(display (compiler.pretty f))
(compiler.parse f gen)
- (eval (gen.get-code))))
+ (eval (gen.get-code))
+ ))
Oops, something went wrong.

0 comments on commit 960b416

Please sign in to comment.