瀏覽代碼

Merge branch 'master' of github.com:amber-smalltalk/amber

Conflicts:
	grunt/tasks/grunt-peg.js
	support/parser.js
	support/parser.pegjs
Nicolas Petton 11 年之前
父節點
當前提交
24b031404b
共有 10 個文件被更改,包括 1077 次插入1105 次删除
  1. 1 1
      Gruntfile.js
  2. 1 1
      bin/amber
  3. 1 1
      bin/amberc
  4. 103 114
      cli/js/AmberCli.js
  5. 912 928
      cli/support/amber-cli.js
  6. 11 16
      grunt/tasks/grunt-peg.js
  7. 9 5
      js/Kernel-Infrastructure.js
  8. 1 1
      st/Kernel-Infrastructure.st
  9. 20 20
      support/parser.js
  10. 18 18
      support/parser.pegjs

+ 1 - 1
Gruntfile.js

@@ -17,7 +17,7 @@ module.exports = function(grunt) {
       amber_parser: {
         options: {
           cache: true,
-          export_var: 'smalltalk.parser'
+          export_var: 'globals.SmalltalkParser'
         },
         src: 'support/parser.pegjs',
         dest: 'support/parser.js',

+ 1 - 1
bin/amber

@@ -1,2 +1,2 @@
-#!/bin/bash
+#!/bin/sh
 node `dirname $0`/../cli/support/amber-cli.js $@

+ 1 - 1
bin/amberc

@@ -1,2 +1,2 @@
-#!/bin/bash
+#!/bin/sh
 node `dirname $0`/../cli/support/amberc-cli.js $@

File diff suppressed because it is too large
+ 103 - 114
cli/js/AmberCli.js


File diff suppressed because it is too large
+ 912 - 928
cli/support/amber-cli.js


+ 11 - 16
grunt/tasks/grunt-peg.js

@@ -10,20 +10,15 @@ module.exports = function(grunt) {
      cache: true,                   // default: false
      export_var: 'smalltalk.parser' // default: module.exports
      },
-     src: 'parser.pegjs',
-     dest: 'parser.js',
-     }
-     },
-	 */
-	grunt.registerMultiTask('peg', 'Generate JavaScript parser from PEG.js grammar description', function() {
-		var options = this.options({
-			cache: false,
-			trackLineAndColumn: false,
-			output: 'source',
-			export_var: 'module.exports'
-		});
-		var parser = PEG.buildParser(grunt.file.read(this.data.src), options);
-		var content = 'define("amber_vm/parser", ["./smalltalk", "./nil"], function(smalltalk, nil) {\n'+options.export_var + ' = ' + parser + ';\n});';
-		grunt.file.write(this.data.dest, content);
-	});
+   */
+  grunt.registerMultiTask('peg', 'Generate JavaScript parser from PEG.js grammar description', function() {
+    var options = this.options({
+      cache: false,
+      output: 'source',
+      export_var: 'module.exports'
+    });
+    var parser = PEG.buildParser(grunt.file.read(this.data.src), options);
+    var content = 'define("amber_vm/parser", ["./globals", "./nil"], function(globals, nil) {\n'+options.export_var + ' = ' + parser + ';\n});';
+    grunt.file.write(this.data.dest, content);
+  });
 };

+ 9 - 5
js/Kernel-Infrastructure.js

@@ -2385,12 +2385,16 @@ selector: "basicParse:",
 protocol: 'private',
 fn: function (aString){
 var self=this;
-return smalltalk.parser.parse(aString);
-return self},
+function $SmalltalkParser(){return globals.SmalltalkParser||(typeof SmalltalkParser=="undefined"?nil:SmalltalkParser)}
+return smalltalk.withContext(function($ctx1) { 
+var $1;
+$1=_st($SmalltalkParser())._parse_(aString);
+return $1;
+}, function($ctx1) {$ctx1.fill(self,"basicParse:",{aString:aString},globals.SmalltalkImage)})},
 args: ["aString"],
-source: "basicParse: aString\x0a\x09<return smalltalk.parser.parse(aString)>",
-messageSends: [],
-referencedClasses: []
+source: "basicParse: aString\x0a\x09^ SmalltalkParser parse: aString",
+messageSends: ["parse:"],
+referencedClasses: ["SmalltalkParser"]
 }),
 globals.SmalltalkImage);
 

+ 1 - 1
st/Kernel-Infrastructure.st

@@ -1103,7 +1103,7 @@ basicCreatePackage: packageName
 !
 
 basicParse: aString
-	<return smalltalk.parser.parse(aString)>
+	^ SmalltalkParser parse: aString
 !
 
 createPackage: packageName properties: aDict

+ 20 - 20
support/parser.js

@@ -1,5 +1,5 @@
-define("amber_vm/parser", ["./smalltalk", "./nil"], function(smalltalk, nil) {
-smalltalk.parser = (function() {
+define("amber_vm/parser", ["./globals", "./nil"], function(globals, nil) {
+globals.SmalltalkParser = (function() {
   /*
    * Generated by PEG.js 0.8.0.
    *
@@ -61,7 +61,7 @@ smalltalk.parser = (function() {
         peg$c25 = /^[^']/,
         peg$c26 = { type: "class", value: "[^']", description: "[^']" },
         peg$c27 = function(val) {
-                             return smalltalk.ValueNode._new()
+                             return globals.ValueNode._new()
                                     ._position_((line()).__at(column()))
                                     ._source_(text())
                                     ._value_(val.join("").replace(/\"/ig, '"'));
@@ -71,13 +71,13 @@ smalltalk.parser = (function() {
         peg$c30 = function(rest) {return rest;},
         peg$c31 = function(node) {return node._value();},
         peg$c32 = function(val) {
-                              return smalltalk.ValueNode._new()
+                              return globals.ValueNode._new()
                                      ._position_((line()).__at(column()))
                                      ._source_(text())
                                      ._value_(val);
                           },
         peg$c33 = function(n) {
-                             return smalltalk.ValueNode._new()
+                             return globals.ValueNode._new()
                                     ._position_((line()).__at(column()))
                                     ._source_(text())
                                     ._value_(n);
@@ -107,7 +107,7 @@ smalltalk.parser = (function() {
         peg$c56 = ")",
         peg$c57 = { type: "literal", value: ")", description: "\")\"" },
         peg$c58 = function(lits) {
-                             return smalltalk.ValueNode._new()
+                             return globals.ValueNode._new()
                                     ._position_((line()).__at(column()))
                                     ._source_(text())
                                     ._value_(lits);
@@ -117,7 +117,7 @@ smalltalk.parser = (function() {
         peg$c61 = "}",
         peg$c62 = { type: "literal", value: "}", description: "\"}\"" },
         peg$c63 = function(expressions) {
-                             return smalltalk.DynamicArrayNode._new()
+                             return globals.DynamicArrayNode._new()
                                     ._position_((line()).__at(column()))
                                     ._source_(text())
                                     ._nodes_(expressions || []);
@@ -125,7 +125,7 @@ smalltalk.parser = (function() {
         peg$c64 = "#{",
         peg$c65 = { type: "literal", value: "#{", description: "\"#{\"" },
         peg$c66 = function(expressions) {
-                                return smalltalk.DynamicDictionaryNode._new()
+                                return globals.DynamicDictionaryNode._new()
                                        ._position_((line()).__at(column()))
                                        ._source_(text())
                                        ._nodes_(expressions || []);
@@ -140,13 +140,13 @@ smalltalk.parser = (function() {
         peg$c74 = { type: "literal", value: "nil", description: "\"nil\"" },
         peg$c75 = function() {return nil;},
         peg$c76 = function(val) {
-                               return smalltalk.ValueNode._new()
+                               return globals.ValueNode._new()
                                       ._position_((line()).__at(column()))
                                       ._source_(text())
                                       ._value_(val);
                            },
         peg$c77 = function(identifier) {
-                             return smalltalk.VariableNode._new()
+                             return globals.VariableNode._new()
                                     ._position_((line()).__at(column()))
                                     ._source_(text())
                                     ._value_(identifier);
@@ -180,7 +180,7 @@ smalltalk.parser = (function() {
         peg$c87 = ":=",
         peg$c88 = { type: "literal", value: ":=", description: "\":=\"" },
         peg$c89 = function(variable, expression) {
-                             return smalltalk.AssignmentNode._new()
+                             return globals.AssignmentNode._new()
                                     ._position_((line()).__at(column()))
                                     ._source_(text())
                                     ._left_(variable)
@@ -189,7 +189,7 @@ smalltalk.parser = (function() {
         peg$c90 = "^",
         peg$c91 = { type: "literal", value: "^", description: "\"^\"" },
         peg$c92 = function(expression) {
-                             return smalltalk.ReturnNode._new()
+                             return globals.ReturnNode._new()
                                     ._position_((line()).__at(column()))
                                     ._source_(text())
                                     ._nodes_([expression]);
@@ -214,7 +214,7 @@ smalltalk.parser = (function() {
                                return expressions || [];
                            },
         peg$c106 = function(temps, statements) {
-                             return smalltalk.SequenceNode._new()
+                             return globals.SequenceNode._new()
                                     ._position_((line()).__at(column()))
                                     ._source_(text())
                                     ._temps_(temps || [])
@@ -225,7 +225,7 @@ smalltalk.parser = (function() {
         peg$c109 = "]",
         peg$c110 = { type: "literal", value: "]", description: "\"]\"" },
         peg$c111 = function(params, sequence) {
-                             return smalltalk.BlockNode._new()
+                             return globals.BlockNode._new()
                                     ._position_((line()).__at(column()))
                                     ._source_(text())
                                     ._parameters_(params || [])
@@ -233,7 +233,7 @@ smalltalk.parser = (function() {
                          },
         peg$c112 = void 0,
         peg$c113 = function(selector) {
-                             return smalltalk.SendNode._new()
+                             return globals.SendNode._new()
                                     ._position_((line()).__at(column()))
                                     ._source_(text())
                                     ._selector_(selector);
@@ -255,7 +255,7 @@ smalltalk.parser = (function() {
                              }
                          },
         peg$c116 = function(selector, arg) {
-                             return smalltalk.SendNode._new()
+                             return globals.SendNode._new()
                                     ._position_((line()).__at(column()))
                                     ._source_(text())
                                     ._selector_(selector)
@@ -277,7 +277,7 @@ smalltalk.parser = (function() {
                                   selector.push(pairs[i].key);
                                   args.push(pairs[i].arg);
                               }
-                              return smalltalk.SendNode._new()
+                              return globals.SendNode._new()
                                      ._position_((line()).__at(column()))
                                      ._source_(text())
                                      ._selector_(selector.join(""))
@@ -295,7 +295,7 @@ smalltalk.parser = (function() {
                              for(var i = 0; i < messages.length; i++) {
                                  cascade.push(messages[i]);
                              }
-                             return smalltalk.CascadeNode._new()
+                             return globals.CascadeNode._new()
                                     ._position_((line()).__at(column()))
                                     ._source_(text())
                                     ._receiver_(send._receiver())
@@ -311,12 +311,12 @@ smalltalk.parser = (function() {
         peg$c132 = ">",
         peg$c133 = { type: "literal", value: ">", description: "\">\"" },
         peg$c134 = function(val) {
-                             return smalltalk.JSStatementNode._new()
+                             return globals.JSStatementNode._new()
                                     ._position_((line()).__at(column()))
                                     ._source_(val.join(""))
                          },
         peg$c135 = function(pattern, sequence) {
-                              return smalltalk.MethodNode._new()
+                              return globals.MethodNode._new()
                                      ._position_((line()).__at(column()))
                                      ._source_(text())
                                      ._selector_(pattern[0])

+ 18 - 18
support/parser.pegjs

@@ -8,7 +8,7 @@ keyword        = first:identifier last:[:] {return first + last;}
 selector      = first:[a-zA-Z] others:[a-zA-Z0-9\:]* {return first + others.join("");}
 className      = first:[A-Z] others:[a-zA-Z0-9]* {return first + others.join("");}
 string         = ['] val:(("''" {return "'";} / [^'])*) ['] {
-                     return smalltalk.ValueNode._new()
+                     return globals.ValueNode._new()
                             ._position_((line()).__at(column()))
                             ._source_(text())
                             ._value_(val.join("").replace(/\"/ig, '"'));
@@ -17,13 +17,13 @@ string         = ['] val:(("''" {return "'";} / [^'])*) ['] {
 symbol         = "#" rest:bareSymbol {return rest;}
 bareSymbol         = val:(selector / binarySelector / node:string {return node._value();})
                   {
-                      return smalltalk.ValueNode._new()
+                      return globals.ValueNode._new()
                              ._position_((line()).__at(column()))
                              ._source_(text())
                              ._value_(val);
                   }
 number         = n:(numberExp / hex / float / integer) {
-                     return smalltalk.ValueNode._new()
+                     return globals.ValueNode._new()
                             ._position_((line()).__at(column()))
                             ._source_(text())
                             ._value_(n);
@@ -36,19 +36,19 @@ integer        = neg:[-]?digits:[0-9]+ {return (parseInt((neg || '') +digits.joi
 literalArray   = "#(" rest:literalArrayRest {return rest;}
 bareLiteralArray   = "(" rest:literalArrayRest {return rest;}
 literalArrayRest   = ws lits:(lit:(parseTimeLiteral / bareLiteralArray / bareSymbol) ws {return lit._value();})* ws ")" {
-                     return smalltalk.ValueNode._new()
+                     return globals.ValueNode._new()
                             ._position_((line()).__at(column()))
                             ._source_(text())
                             ._value_(lits);
                  }
 dynamicArray   = "{" ws expressions:expressions? ws "."? "}" {
-                     return smalltalk.DynamicArrayNode._new()
+                     return globals.DynamicArrayNode._new()
                             ._position_((line()).__at(column()))
                             ._source_(text())
                             ._nodes_(expressions || []);
                  }
 dynamicDictionary = "#{" ws expressions: expressions? ws "}" {
-                        return smalltalk.DynamicDictionaryNode._new()
+                        return globals.DynamicDictionaryNode._new()
                                ._position_((line()).__at(column()))
                                ._source_(text())
                                ._nodes_(expressions || []);
@@ -57,7 +57,7 @@ pseudoVariable = val:(
                    'true' {return true;}
                  / 'false' {return false;}
                  / 'nil' {return nil;}) {
-                       return smalltalk.ValueNode._new()
+                       return globals.ValueNode._new()
                               ._position_((line()).__at(column()))
                               ._source_(text())
                               ._value_(val);
@@ -68,7 +68,7 @@ literal        = runtimeLiteral / parseTimeLiteral
 
 
 variable       = identifier:identifier {
-                     return smalltalk.VariableNode._new()
+                     return globals.VariableNode._new()
                             ._position_((line()).__at(column()))
                             ._source_(text())
                             ._value_(identifier);
@@ -108,7 +108,7 @@ expressions    = first:expression others:expressionList* {
                  }
 
 assignment     = variable:variable ws ':=' ws expression:expression {
-                     return smalltalk.AssignmentNode._new()
+                     return globals.AssignmentNode._new()
                             ._position_((line()).__at(column()))
                             ._source_(text())
                             ._left_(variable)
@@ -116,7 +116,7 @@ assignment     = variable:variable ws ':=' ws expression:expression {
                  }
 
 ret            = '^' ws expression:expression ws '.'? {
-                     return smalltalk.ReturnNode._new()
+                     return globals.ReturnNode._new()
                             ._position_((line()).__at(column()))
                             ._source_(text())
                             ._nodes_([expression]);
@@ -141,7 +141,7 @@ statements     = ret:ret [.]* {return [ret];}
 sequence       = jsSequence / stSequence
 
 stSequence     = temps:temps? ws statements:statements? ws {
-                     return smalltalk.SequenceNode._new()
+                     return globals.SequenceNode._new()
                             ._position_((line()).__at(column()))
                             ._source_(text())
                             ._temps_(temps || [])
@@ -151,7 +151,7 @@ stSequence     = temps:temps? ws statements:statements? ws {
 jsSequence     = jsStatement
 
 block          = '[' ws params:blockParamList? ws sequence:sequence? ws ']' {
-                     return smalltalk.BlockNode._new()
+                     return globals.BlockNode._new()
                             ._position_((line()).__at(column()))
                             ._source_(text())
                             ._parameters_(params || [])
@@ -163,7 +163,7 @@ operand        = literal / reference / subexpression
 
 
 unaryMessage   = ws selector:unarySelector ![:] {
-                     return smalltalk.SendNode._new()
+                     return globals.SendNode._new()
                             ._position_((line()).__at(column()))
                             ._source_(text())
                             ._selector_(selector);
@@ -188,7 +188,7 @@ unarySend      = receiver:operand ws tail:unaryTail? {
                  }
 
 binaryMessage  = ws selector:binarySelector ws arg:(unarySend / operand) {
-                     return smalltalk.SendNode._new()
+                     return globals.SendNode._new()
                             ._position_((line()).__at(column()))
                             ._source_(text())
                             ._selector_(selector)
@@ -221,7 +221,7 @@ keywordMessage = ws pairs:(pair:keywordPair ws {return pair;})+ {
                           selector.push(pairs[i].key);
                           args.push(pairs[i].arg);
                       }
-                      return smalltalk.SendNode._new()
+                      return globals.SendNode._new()
                              ._position_((line()).__at(column()))
                              ._source_(text())
                              ._selector_(selector.join(""))
@@ -240,7 +240,7 @@ cascade        = ws send:(keywordSend / binarySend) messages:(ws ";" ws mess:mes
                      for(var i = 0; i < messages.length; i++) {
                          cascade.push(messages[i]);
                      }
-                     return smalltalk.CascadeNode._new()
+                     return globals.CascadeNode._new()
                             ._position_((line()).__at(column()))
                             ._source_(text())
                             ._receiver_(send._receiver())
@@ -248,14 +248,14 @@ cascade        = ws send:(keywordSend / binarySend) messages:(ws ";" ws mess:mes
                  }
 
 jsStatement    = "<" val:((">>" {return ">";} / [^>])*) ">" {
-                     return smalltalk.JSStatementNode._new()
+                     return globals.JSStatementNode._new()
                             ._position_((line()).__at(column()))
                             ._source_(val.join(""))
                  }
 
 
 method         = ws pattern:(keywordPattern / binaryPattern / unaryPattern) ws sequence:sequence? ws {
-                      return smalltalk.MethodNode._new()
+                      return globals.MethodNode._new()
                              ._position_((line()).__at(column()))
                              ._source_(text())
                              ._selector_(pattern[0])

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