Permalink
Browse files

update previous compiler with bugfixes/tweaks so it can compile new r…

…ewritten version of Outlet
  • Loading branch information...
1 parent b5b3cd1 commit 41541055becffc90063822ac53057e4b3e59d1fd @jlongster committed Feb 10, 2012
Showing with 2,038 additions and 436 deletions.
  1. +28 −18 compiler-js.js
  2. +202 −1 compiler.js
  3. +1 −1 compiler.ol
  4. +204 −2 grammar.js
  5. +204 −2 parser.js
  6. BIN read/eps.pdf
  7. +201 −1 runtime.js
  8. +0 −89 web/examples.ol
  9. +0 −2 web/index.html
  10. +1 −0 web/runtime-eval.js
  11. +247 −37 web/runtime.js
  12. +0 −19 web/test.js
  13. +6 −1 web/ui.js
  14. +944 −263 web/web.js
View
@@ -64,6 +64,16 @@ function generator() {
}
}
+ function transform_symbol(str) {
+ str = str.replace(/-/g, '_dash_');
+ str = str.replace(/\?/g, '_p_');
+ str = str.replace(/\!/g, '_excl_');
+ str = str.replace(/>/g, '_gt_');
+ str = str.replace(/</g, '_lt_');
+ str = str.replace(/%/g, '_per_');
+ return str;
+ }
+
function write_number(node) {
// NUMBER
write(node.data);
@@ -82,19 +92,12 @@ function generator() {
function write_term(node) {
// TERM (variable, keyword, etc)
- var term = node.data.str;
- term = term.replace(/-/g, '_');
- term = term.replace(/\?/g, '_p_');
- term = term.replace(/\!/g, '_excl_');
- term = term.replace(/>/g, '_gt_');
- term = term.replace(/</g, '_lt_');
- term = term.replace(/%/g, '_per_');
- write(term);
+ write(transform_symbol(node.data.str));
}
function write_symbol(node) {
// SYMBOL
- write('make_symbol("' + node.data.str + '")');
+ write('string_dash__gt_symbol("' + transform_symbol(node.data.str) + '")');
}
function write_set(node, parse) {
@@ -125,8 +128,7 @@ function generator() {
// support for dot-style rest arguments
if(arg.data.str == '.') {
- var name = args_expr.children[i+1];
- capture_name = name.data.str;
+ capture_name = args_expr.children[i+1];
break;
}
else {
@@ -141,15 +143,16 @@ function generator() {
write('){', true);
if(capture_name) {
- write('var ' + capture_name +
- ' = vector_to_list(Array.prototype.slice.call(arguments, ' +
+ write('var ');
+ write_term(capture_name);
+ write(' = vector_dash_to_dash_list(Array.prototype.slice.call(arguments, ' +
(args_expr.children.length - 2) + '));', true);
}
}
else {
write('function() {', true);
write('var ' + args_expr.data.str +
- ' = vector_to_list(Array.prototype.slice.call(arguments));', true);
+ ' = vector_dash_to_dash_list(Array.prototype.slice.call(arguments));', true);
}
for(var i=2, len=node.children.length; i<len; i++) {
@@ -256,7 +259,7 @@ function generator() {
- write('"' + key + '": ');
+ write('"' + transform_symbol(key) + '": ');
write_list_element(node, val_index, parse, context);
}
@@ -271,14 +274,14 @@ function generator() {
function _write_list(node, i, parse, context) {
if(i < node.children.length) {
- write('make_list([');
+ write('make_dash_list([');
write_list_element(node, i, parse, context);
write(',');
_write_list(node, i+1, parse, context);
write('])');
}
else {
- write('[]');
+ write('_emptylst');
}
}
@@ -385,7 +388,14 @@ function generator() {
write('}');
}
- write('})()', true);
+ write('})()');
+
+ if(!node.link ||
+ (node.link && node.link.tag != 'expr')) {
+ write(';');
+ }
+
+ write('\n');
},
'and': function(node, parse) {
View
@@ -1,5 +1,7 @@
var util = require('util');
+var _emptylst = [];
+
function make_symbol(str) {
return {
str: str,
@@ -380,6 +382,205 @@ function unquote_splice_map(obj) {
return res;
}
+
+
+
+
+
+
+// updated
+
+function for_dash_each(func, lst) {
+ if(!null_p_(lst)) {
+ func(car(lst));
+ for_each(func, cdr(lst));
+ }
+}
+
+function make_dash_vector(i) {
+ return new Array(i);
+}
+
+function vector_dash_map(func, vec) {
+ var res = [];
+
+ for(var i=0, len=vec.length; i<len; i++) {
+ res.push(func(vec[i]));
+ }
+
+ return res;
+}
+
+function vector_dash_for_dash_each(func, vec) {
+ for(var i=0, len=vec.length; i<len; i++) {
+ func(vec[i]);
+ }
+}
+
+
+function make_dash_list(arr) {
+ arr.list = true;
+ return arr;
+}
+
+function vector_dash_to_dash_list(vec) {
+ function l(v, i) {
+ if(i < v.length) {
+ return cons(v[i], l(v, i+1));
+ }
+ else {
+ return _emptylst;
+ }
+ }
+
+ return l(vec, 0);
+}
+
+function list_dash_to_dash_vector(lst) {
+ var res = [];
+
+ function m(lst) {
+ if(!null_p_(lst)) {
+ res.push(car(lst));
+ m(cdr(lst));
+ }
+ };
+
+ m(lst);
+ return res;
+}
+
+function vector_dash_ref(arr, i) {
+ return arr[i];
+}
+
+function vector_dash_set_excl_(arr, i, v) {
+ arr[i] = v;
+}
+
+function vector_dash_concat(arr1, arr2) {
+ return arr1.concat(arr2);
+}
+
+function vector() {
+ return Array.prototype.slice.call(arguments);
+}
+
+function vector_dash_push(vec, val) {
+ vec.push(val);
+}
+
+function hash_dash_map() {
+ var keyvals = Array.prototype.slice.call(arguments);
+ var res = {};
+
+ for(var i=0, len=keyvals.length; i<len; i+=2) {
+ var key = keyvals[i];
+
+ // Ignore this, it's only to support the compiler for now...
+ if(key.children &&
+ key.children.length > 0 &&
+ key.children[0].data &&
+ key.children[0].data.str &&
+ key.children[0].data.str == 'quote') {
+ key = key.children[1].data.str;
+ }
+ else if(key.str) {
+ key = key.str;
+ }
+
+ res[key] = keyvals[i+1];
+ }
+
+ return res;
+}
+
+function hash_dash_map_dash_map(func, m) {
+ var res = {};
+ for(var k in m) {
+ res[k] = func(m[k]);
+ }
+ return res;
+}
+
+function hash_dash_map_dash_to_dash_vec(obj) {
+ var res = [];
+ for(var k in obj) {
+ res.push(vector_to_list([make_symbol('quote'), make_symbol(k)]));
+ res.push(obj[k]);
+ }
+ return res;
+}
+
+function object_dash_ref(obj, key) {
+ return obj[key];
+}
+
+
+function _dash__gt_string(obj) {
+ if(number_p_(obj)) {
+ return '' + obj;
+ }
+ else if(string_p_(obj)) {
+ return '"' + obj.replace(/"/g, "\\\"") + '"';
+ }
+ else if(symbol_p_(obj)) {
+ return obj.str;
+ }
+ else if(boolean_p_(obj)) {
+ if(obj) {
+ return '#t';
+ }
+ else {
+ return '#f';
+ }
+ }
+ else if(list_p_(obj)) {
+ return '(' +
+ map(function(obj) { return __gt_string(obj); },
+ obj).join(' ') +
+ ')';
+ }
+ else if(vector_p_(obj)) {
+ return '[' +
+ vector_map(function(obj) { return __gt_string(obj); },
+ obj).join(' ') +
+ ']';
+ }
+ else if(map_p_(obj)) {
+ var res = [];
+ for(var k in obj) {
+ res.push(k + ': ' + util.inspect(obj[k], null, 10));
+ }
+ return '{' + res.join(', ') + '}';
+ }
+}
+
+function list_dash_append(lst1, lst2) {
+ function loop(lst) {
+ if(null_p_(lst)) {
+ return lst2;
+ }
+ else {
+ return cons(car(lst), loop(cdr(lst)));
+ }
+ };
+
+ if(null_p_(lst1)) {
+ return lst2;
+ }
+ else {
+ return loop(lst1);
+ }
+}
+
+function string_dash__gt_symbol(str) {
+ return {
+ str: str,
+ symbol: true
+ };
+}
+
var util = require("util");
var fs = require("fs");
var reader = require("./parser");
@@ -394,7 +595,7 @@ return assert((node.type===type),("invalid type, expected "+type+": "+inspect(no
;var parsers = unquote_splice([]);var install_builtin_macros = function(){
return (function(src){
return parse(read(src),create_generator());}
-)(fs.readFileSync("macros.ol","utf-8"));}
+)(fs.readFileSync((__dirname+"/macros.ol"),"utf-8"));}
;var read = function(src){
return reader(grammar,src,ast.node(ast.ROOT));}
;var set_generator = function(gen){
View
@@ -25,7 +25,7 @@
(define parsers '())
(define (install-builtin-macros)
- (let ((src (fs.readFileSync "macros.ol" "utf-8")))
+ (let ((src (fs.readFileSync (+ __dirname "/macros.ol") "utf-8")))
(parse (read src) (create-generator))))
(define (read src)
Oops, something went wrong.

0 comments on commit 4154105

Please sign in to comment.