瀏覽代碼

Merge pull request #386 from mkroehnert/amberc

amberc, server, and grunt.js fixes
Nicolas Petton 11 年之前
父節點
當前提交
bb7daed39e
共有 9 個文件被更改,包括 924 次插入577 次删除
  1. 2 9
      Makefile
  2. 1 1
      bin/amberc
  3. 4 4
      bin/amberc.js
  4. 1 1
      bin/server
  5. 1 7
      grunt.js
  6. 34 34
      repl/REPL.js
  7. 436 258
      repl/amber.js
  8. 8 4
      server/FileServer.st
  9. 437 259
      server/server.js

+ 2 - 9
Makefile

@@ -2,17 +2,15 @@
 AMBER = st
 SERVER = server
 REPL = repl
-EXAMPLES = examples
 
 # REST is all except AMBER
-REST = $(SERVER) $(EXAMPLES) $(REPL)
+REST = $(SERVER) $(REPL)
 
 # And these are all
 DIRS = $(AMBER) $(REST)
 
 # The sets of directories to do various things in
 BUILDDIRS = $(DIRS:%=build-%)
-EXAMPLESDIRS = $(EXAMPLES:%=build-%)
 INSTALLDIRS = $(AMBER:%=install-%)
 CLEANDIRS = $(REST:%=clean-%)
 CLEANALLDIRS = $(DIRS:%=clean-%)
@@ -24,13 +22,8 @@ $(BUILDDIRS):
 
 amber: build-st
 
-# Examples and server need Amber first
+# server needs Amber first
 build-server: build-st
-build-examples: build-st
-
-examples: $(EXAMPLESDIRS)
-$(EXAMPLESDIRS):
-	$(MAKE) -C $(@:build-%=%)
 
 install: $(INSTALLDIRS)
 $(INSTALLDIRS):

+ 1 - 1
bin/amberc

@@ -20,7 +20,7 @@ var amber_dir = path.normalize(path.join(path.dirname(process.argv[1]), '..'));
 // Get default location of compiler.jar
 var closure_jar = path.resolve(path.join(process.env['HOME'], 'compiler.jar'));
 
-var compiler = new amberc.Compiler(amber_dir);
+var compiler = new amberc.Compiler(amber_dir, closure_jar);
 
 var configuration = handle_options(parameters, amber_dir);
 

+ 4 - 4
bin/amberc.js

@@ -82,7 +82,7 @@ var path = require('path'),
  */
 function AmberC(amber_dir, closure_jar) {
 	this.amber_dir = amber_dir;
-	this.closure_jar = closure_jar;
+	this.closure_jar = closure_jar || '';
 	this.kernel_libraries = ['boot', 'Kernel-Objects', 'Kernel-Classes', 'Kernel-Methods',
 	                         'Kernel-Collections', 'Kernel-Exceptions', 'Kernel-Transcript',
 	                         'Kernel-Announcements'];
@@ -580,13 +580,13 @@ AmberC.prototype.optimize = function() {
 
 	if (defaults.closure_parts) {
 		console.log('Compiling all js files using Google closure compiler.');
-		var allJsFiles = defaults.compiled.concat(defaults.libraries);
-		allJsFiles.forEach(function(file) {
+		defaults.compiled.forEach(function(file) {
+			console.log('Compiling ' + file + ' file using Google closure compiler.');
 			var minifiedName = path.basename(file, '.js') + '.min.js';
 			self.closure_compile(file, minifiedName, optimization_done.add());
 		});
 	}
-	if (defaults.closure_full) {
+	if (defaults.closure_full && (undefined !== defaults.program)) {
 		console.log('Compiling ' + defaults.program + '.js file using Google closure compiler.');
 		self.closure_compile(defaults.program + '.js', defaults.program + '.min.js', optimization_done.add());
 	}

+ 1 - 1
bin/server

@@ -1,3 +1,3 @@
 #!/bin/bash
 cd `dirname $0`/..
-node ./server/server.js
+node ./server/server.js $@

+ 1 - 7
grunt.js

@@ -66,12 +66,6 @@ module.exports = function(grunt) {
         src: ['Kernel-Tests.st', 'Compiler-Tests.st'],
         libraries: ['SUnit']
       },
-      amber_examples: {
-        working_dir: 'st',
-        target_dir : 'js',
-        src: ['Examples.st'],
-        libraries: ['Canvas', 'IDE']
-      },
       amber_dev: {
         working_dir: 'js',
         src: ['Kernel-Objects.js', 'Kernel-Classes.js', 'Kernel-Methods.js', 'Kernel-Collections.js',
@@ -79,7 +73,7 @@ module.exports = function(grunt) {
               'Compiler.js', 'Compiler-Exceptions.js', 'Compiler-Core.js', 'Compiler-AST.js',
               'Compiler-IR.js', 'Compiler-Inlining.js', 'Compiler-Semantic.js',
               'Kernel-Tests.js', 'Compiler-Tests.js',
-              'Canvas.js', 'IDE.js', 'SUnit.js', 'Documentation.js', 'Examples.js'],
+              'Canvas.js', 'IDE.js', 'SUnit.js', 'Documentation.js'],
         output_name: 'amber_lib'
       },
       server: {

+ 34 - 34
repl/REPL.js

@@ -7,8 +7,8 @@ selector: "close",
 category: 'actions',
 fn: function (){
 var self=this;
-smalltalk.send(smalltalk.send(process,"_stdin",[]),"_destroy",[]);
-return self},
+return smalltalk.withContext(function($ctx1) { 
_st(_st(process)._stdin())._destroy();
+return self}, function($ctx1) {$ctx1.fill(self,"close",{}, smalltalk.Repl)})},
 args: [],
 source: "close\x0a\x09process stdin destroy",
 messageSends: ["destroy", "stdin"],
@@ -23,16 +23,16 @@ selector: "createInterface",
 category: 'actions',
 fn: function (){
 var self=this;
-self["@interface"]=smalltalk.send(self["@readline"],"_createInterface_stdout_",[smalltalk.send(process,"_stdin",[]),smalltalk.send(process,"_stdout",[])]);
-smalltalk.send(self["@interface"],"_on_do_",["line",(function(buffer){
-return smalltalk.send(self,"_eval_",[buffer]);
-})]);
-smalltalk.send(self["@interface"],"_on_do_",["close",(function(){
-return smalltalk.send(self,"_close",[]);
-})]);
-smalltalk.send(self,"_setPrompt",[]);
-smalltalk.send(self["@interface"],"_prompt",[]);
-return self},
+return smalltalk.withContext(function($ctx1) { 
self["@interface"]=_st(self["@readline"])._createInterface_stdout_(_st(process)._stdin(),_st(process)._stdout());
+_st(self["@interface"])._on_do_("line",(function(buffer){
+return smalltalk.withContext(function($ctx2) {
return _st(self)._eval_(buffer);
+}, function($ctx2) {$ctx2.fillBlock({buffer:buffer},$ctx1)})}));
+_st(self["@interface"])._on_do_("close",(function(){
+return smalltalk.withContext(function($ctx2) {
return _st(self)._close();
+}, function($ctx2) {$ctx2.fillBlock({},$ctx1)})}));
+_st(self)._setPrompt();
+_st(self["@interface"])._prompt();
+return self}, function($ctx1) {$ctx1.fill(self,"createInterface",{}, smalltalk.Repl)})},
 args: [],
 source: "createInterface\x0a\x09\x22No completion for now\x22\x0a\x09interface := readline createInterface: process stdin stdout: process stdout.\x0a\x09interface on: 'line' do: [:buffer  | self eval: buffer].\x0a\x09interface on: 'close' do: [self close].\x0a\x09self setPrompt.\x0a\x09interface prompt",
 messageSends: ["createInterface:stdout:", "stdin", "stdout", "on:do:", "eval:", "close", "setPrompt", "prompt"],
@@ -47,25 +47,25 @@ selector: "eval:",
 category: 'actions',
 fn: function (buffer){
 var self=this;
-var $1,$2;
 var result;
-$1=smalltalk.send(buffer,"_isEmpty",[]);
+return smalltalk.withContext(function($ctx1) { 
var $1,$2;
+$1=_st(buffer)._isEmpty();
 if(! smalltalk.assert($1)){
-smalltalk.send(self,"_try_catch_",[(function(){
-result=smalltalk.send(smalltalk.send((smalltalk.Compiler || Compiler),"_new",[]),"_evaluateExpression_",[buffer]);
+_st(self)._try_catch_((function(){
+return smalltalk.withContext(function($ctx2) {
result=_st(_st((smalltalk.Compiler || Compiler))._new())._evaluateExpression_(buffer);
 result;
-return smalltalk.send((smalltalk.Transcript || Transcript),"_show_",[result]);
-}),(function(e){
-$2=smalltalk.send(e,"_isSmalltalkError",[]);
+return _st((smalltalk.Transcript || Transcript))._show_(result);
+}, function($ctx2) {$ctx2.fillBlock({},$ctx1)})}),(function(e){
+return smalltalk.withContext(function($ctx2) {
$2=_st(e)._isSmalltalkError();
 if(smalltalk.assert($2)){
-return smalltalk.send(smalltalk.send((smalltalk.ErrorHandler || ErrorHandler),"_new",[]),"_handleError_",[e]);
+return _st(_st((smalltalk.ErrorHandler || ErrorHandler))._new())._handleError_(e);
 } else {
-return smalltalk.send(smalltalk.send(process,"_stdout",[]),"_write_",[smalltalk.send(e,"_jsStack",[])]);
+return _st(_st(process)._stdout())._write_(_st(e)._jsStack());
 };
-})]);
+}, function($ctx2) {$ctx2.fillBlock({e:e},$ctx1)})}));
 };
-smalltalk.send(self["@interface"],"_prompt",[]);
-return self},
+_st(self["@interface"])._prompt();
+return self}, function($ctx1) {$ctx1.fill(self,"eval:",{buffer:buffer,result:result}, smalltalk.Repl)})},
 args: ["buffer"],
 source: "eval: buffer\x0a\x09| result |\x0a\x09buffer isEmpty ifFalse: [\x0a\x09\x09self try: [\x0a\x09\x09\x09result := Compiler new evaluateExpression: buffer.\x0a\x09\x09\x09Transcript show: result]\x0a\x09\x09catch: [:e |\x0a\x09\x09\x09e isSmalltalkError\x0a\x09\x09\x09    ifTrue: [ErrorHandler new handleError: e]\x0a\x09\x09\x09    ifFalse: [process stdout write: e jsStack]]].\x0a\x09interface prompt",
 messageSends: ["ifFalse:", "try:catch:", "evaluateExpression:", "new", "show:", "ifTrue:ifFalse:", "handleError:", "write:", "jsStack", "stdout", "isSmalltalkError", "isEmpty", "prompt"],
@@ -80,10 +80,10 @@ selector: "initialize",
 category: 'initialization',
 fn: function (){
 var self=this;
-smalltalk.send(self,"_initialize",[],smalltalk.Object);
-self["@readline"]=smalltalk.send(require,"_value_",["readline"]);
-self["@util"]=smalltalk.send(require,"_value_",["util"]);
-return self},
+return smalltalk.withContext(function($ctx1) { 
smalltalk.Object.fn.prototype._initialize.apply(_st(self), []);
+self["@readline"]=_st(require)._value_("readline");
+self["@util"]=_st(require)._value_("util");
+return self}, function($ctx1) {$ctx1.fill(self,"initialize",{}, smalltalk.Repl)})},
 args: [],
 source: "initialize\x0a\x09super initialize.\x0a\x09readline := require value: 'readline'.\x0a\x09util := require value: 'util'",
 messageSends: ["initialize", "value:"],
@@ -98,8 +98,8 @@ selector: "prompt",
 category: 'accessing',
 fn: function (){
 var self=this;
-return "amber >> ";
-},
+return smalltalk.withContext(function($ctx1) { 
return "amber >> ";
+}, function($ctx1) {$ctx1.fill(self,"prompt",{}, smalltalk.Repl)})},
 args: [],
 source: "prompt\x0a\x09^'amber >> '",
 messageSends: [],
@@ -114,8 +114,8 @@ selector: "setPrompt",
 category: 'actions',
 fn: function (){
 var self=this;
-smalltalk.send(self["@interface"],"_setPrompt_",[smalltalk.send(self,"_prompt",[])]);
-return self},
+return smalltalk.withContext(function($ctx1) { 
_st(self["@interface"])._setPrompt_(_st(self)._prompt());
+return self}, function($ctx1) {$ctx1.fill(self,"setPrompt",{}, smalltalk.Repl)})},
 args: [],
 source: "setPrompt\x0a\x09interface setPrompt: self prompt",
 messageSends: ["setPrompt:", "prompt"],
@@ -131,8 +131,8 @@ selector: "main",
 category: 'not yet classified',
 fn: function (){
 var self=this;
-smalltalk.send(smalltalk.send(self,"_new",[]),"_createInterface",[]);
-return self},
+return smalltalk.withContext(function($ctx1) { 
_st(_st(self)._new())._createInterface();
+return self}, function($ctx1) {$ctx1.fill(self,"main",{}, smalltalk.Repl.klass)})},
 args: [],
 source: "main\x0a\x09self new createInterface",
 messageSends: ["createInterface", "new"],

File diff suppressed because it is too large
+ 436 - 258
repl/amber.js


+ 8 - 4
server/FileServer.st

@@ -67,7 +67,11 @@ writeData: data toFileNamed: aFilename
 	console log: aFilename
 !
 
-isAuthenticated: aRequest response: aResponse
+base64Decode: aString
+	<return (new Buffer(aString, 'base64').toString())>
+!
+
+isAuthenticated: aRequest
 	"Basic HTTP Auth: http://stackoverflow.com/a/5957629/293175
 	 and https://gist.github.com/1686663"
 	| header token auth parts|
@@ -82,7 +86,7 @@ isAuthenticated: aRequest response: aResponse
 		"get authentication token"
 		token := (header tokenize: ' ') ifNil:[''].
 		"convert back from base64"
-		<auth = new Buffer(token[1], 'base64').toString()>.
+		auth := self base64Decode: (token at: 2).
 		"split token at colon"
 		parts := auth tokenize: ':'.
 
@@ -115,8 +119,8 @@ handleGETRequest: aRequest respondTo: aResponse
 
 handlePUTRequest: aRequest respondTo: aResponse
 	| file stream |
-	(self isAuthenticated: aRequest response: aResponse)
-		ifFalse: [self respondAuthenticationRequiredTo: aResponse].
+	(self isAuthenticated: aRequest)
+		ifFalse: [self respondAuthenticationRequiredTo: aResponse. ^nil].
 
 	file := '.', aRequest url.
 	stream := fs createWriteStream: file.

File diff suppressed because it is too large
+ 437 - 259
server/server.js


Some files were not shown because too many files changed in this diff