From c88b1f6a150463eaeb92177271285db474f788a0 Mon Sep 17 00:00:00 2001 From: Jeremy Ashkenas Date: Sat, 13 Feb 2010 10:27:18 -0500 Subject: [PATCH] got the CoffeeScript-in-CoffeeScript REPL running, and boy is she fast --- lib/coffee_script/coffee-script.js | 4 ++-- lib/coffee_script/command_line.js | 2 +- lib/coffee_script/repl.js | 7 +++++-- src/coffee-script.coffee | 4 ++-- src/command_line.coffee | 2 +- src/repl.coffee | 4 ++-- 6 files changed, 13 insertions(+), 10 deletions(-) diff --git a/lib/coffee_script/coffee-script.js b/lib/coffee_script/coffee-script.js index c3fa0eee..2ef3e8b5 100644 --- a/lib/coffee_script/coffee-script.js +++ b/lib/coffee_script/coffee-script.js @@ -26,8 +26,8 @@ }; exports.VERSION = '0.5.0'; // Compile CoffeeScript to JavaScript, using the Coffee/Jison compiler. - exports.compile = function compile(code) { - return (parser.parse(lexer.tokenize(code))).compile(); + exports.compile = function compile(code, options) { + return (parser.parse(lexer.tokenize(code))).compile(options); }; // Just the tokens. exports.tokenize = function tokenize(code) { diff --git a/lib/coffee_script/command_line.js b/lib/coffee_script/command_line.js index 96a6648e..45739505 100644 --- a/lib/coffee_script/command_line.js +++ b/lib/coffee_script/command_line.js @@ -14,7 +14,7 @@ exports.run = function run() { parse_options(); if (options.interactive) { - launch_repl(); + return require('./repl'); } if (!(sources.length)) { usage(); diff --git a/lib/coffee_script/repl.js b/lib/coffee_script/repl.js index 38b59ebd..e4ac6930 100644 --- a/lib/coffee_script/repl.js +++ b/lib/coffee_script/repl.js @@ -11,7 +11,10 @@ }; // The main REPL function. Called everytime a line of code is entered. readline = function readline(code) { - return coffee.ruby_compile(code, run); + return run(coffee.compile(code, { + no_wrap: true, + globals: true + })); }; // Attempt to evaluate the command. If there's an exception, print it. run = function run(js) { @@ -27,7 +30,7 @@ return print(prompt); }; // Start up the REPL. - process.stdio.open(); process.stdio.addListener('data', readline); + process.stdio.open(); print(prompt); })(); \ No newline at end of file diff --git a/src/coffee-script.coffee b/src/coffee-script.coffee index 617300e9..d99231cb 100644 --- a/src/coffee-script.coffee +++ b/src/coffee-script.coffee @@ -20,8 +20,8 @@ parser.lexer: { exports.VERSION: '0.5.0' # Compile CoffeeScript to JavaScript, using the Coffee/Jison compiler. -exports.compile: (code) -> - (parser.parse lexer.tokenize code).compile() +exports.compile: (code, options) -> + (parser.parse lexer.tokenize code).compile(options) # Just the tokens. exports.tokenize: (code) -> diff --git a/src/command_line.coffee b/src/command_line.coffee index 1296c67f..7ab30703 100644 --- a/src/command_line.coffee +++ b/src/command_line.coffee @@ -35,7 +35,7 @@ option_parser: null # The CommandLine handles all of the functionality of the `coffee` utility. exports.run: -> parse_options() - launch_repl() if options.interactive + return require './repl' if options.interactive usage() unless sources.length compile_scripts() this diff --git a/src/repl.coffee b/src/repl.coffee index 724a572f..d52d403a 100644 --- a/src/repl.coffee +++ b/src/repl.coffee @@ -9,7 +9,7 @@ prompt: 'coffee> ' quit: -> process.stdio.close() # The main REPL function. Called everytime a line of code is entered. -readline: (code) -> coffee.ruby_compile code, run +readline: (code) -> run coffee.compile code, {no_wrap: true, globals: true} # Attempt to evaluate the command. If there's an exception, print it. run: (js) -> @@ -21,6 +21,6 @@ run: (js) -> print prompt # Start up the REPL. -process.stdio.open() process.stdio.addListener 'data', readline +process.stdio.open() print prompt \ No newline at end of file