Skip to content

Commit

Permalink
add -o flag to control optimizations, recompile without arg count che…
Browse files Browse the repository at this point in the history
…cking
  • Loading branch information
jlongster committed May 7, 2012
1 parent a6f9de2 commit b9b5596
Show file tree
Hide file tree
Showing 10 changed files with 904 additions and 6,248 deletions.
1,019 changes: 88 additions & 931 deletions ast.js

Large diffs are not rendered by default.

1,463 changes: 266 additions & 1,197 deletions backends/js.js

Large diffs are not rendered by default.

37 changes: 21 additions & 16 deletions backends/js.ol
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,12 @@
(== (ast.first* form) 'set!)
(== (ast.first* form) 'define)))))

(define (generator)
(define (generator & optimizations)
(define code [])

(if (not optimizations)
(set! optimizations 0))

(define (make-fresh)
(generator))

Expand Down Expand Up @@ -187,25 +190,27 @@
(write-args (ast.node-data args) 0)
(write "){" #t)

;; check number of arguments
(write (str "if(arguments.length < " arg-min ") {") #t)
(write (str "throw Error(\""
(or (ast.node-extra name) "lambda")
": not enough arguments\")")
#t)
(write "}" #t)

(if arg-max
(if (< optimizations 1)
(begin
(write (str "else if(arguments.length > "
arg-max
") {")
#t)
;; check number of arguments
(write (str "if(arguments.length < " arg-min ") {") #t)
(write (str "throw Error(\""
(or (ast.node-extra name) "lambda")
": too many arguments\");")
": not enough arguments\")")
#t)
(write "}" #t)))
(write "}" #t)

(if arg-max
(begin
(write (str "else if(arguments.length > "
arg-max
") {")
#t)
(write (str "throw Error(\""
(or (ast.node-extra name) "lambda")
": too many arguments\");")
#t)
(write "}" #t)))))

(cond
(capture-name
Expand Down
20 changes: 13 additions & 7 deletions bin/ol
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ var expand = false;
var amt = false;
var rt = 'js';
var compiler_path = false;
var optimizations = 0;

if(args[0] == '-o') {
optimizations = args[1];
args = args.slice(2);
}

if(args[0] == '-c') {
compile = true;
Expand Down Expand Up @@ -56,22 +62,22 @@ else {
args = args.slice(1);
}

if(expand) {
compiler['set-macro-generator'](js_backend());
compiler['set-optimizations'](optimizations);
var backend = js_backend(optimizations);

if(expand) {
compiler['set-macro-generator'](backend);
compiler.pp(compiler.desourcify(compiler.expand(reader.read(src))));
}
else {
var js = js_backend();

if(compiler_path) {
js['write-runtime'](rt, compiler_path);
backend['write-runtime'](rt, compiler_path);
}
else {
js['write-runtime'](rt);
backend['write-runtime'](rt);
}

var output = compiler["compile-program"](src, js);
var output = compiler["compile-program"](src, backend);

if(compile) {
output = 'var __args = process.argv.slice(2);' + output;
Expand Down
Loading

0 comments on commit b9b5596

Please sign in to comment.