Browse Source

Merge remote-tracking branch 'upstream/master' into classifier

Benjamin Van Ryseghem 11 years ago
parent
commit
ae088463a0
6 changed files with 205 additions and 130 deletions
  1. 52 52
      js/Helios-Helpers.js
  2. 58 57
      js/Kernel-Collections.js
  3. 67 2
      js/Kernel-Tests.js
  4. 6 7
      st/Helios-Helpers.st
  5. 11 11
      st/Kernel-Collections.st
  6. 11 1
      st/Kernel-Tests.st

+ 52 - 52
js/Helios-Helpers.js

@@ -23,6 +23,29 @@ referencedClasses: []
 }),
 smalltalk.HLGenerationOutput);
 
+smalltalk.addMethod(
+smalltalk.method({
+selector: "compile",
+protocol: 'protocol',
+fn: function (){
+var self=this;
+return smalltalk.withContext(function($ctx1) { 
+var $1;
+_st(self["@sourceCodes"])._do_((function(methodSourceCode){
+return smalltalk.withContext(function($ctx2) {
+$1=_st(self["@targetClass"])._includesSelector_(_st(methodSourceCode)._selector());
+if(! smalltalk.assert($1)){
+return _st(self["@targetClass"])._compile_protocol_(_st(methodSourceCode)._sourceCode(),self["@protocol"]);
+};
+}, function($ctx2) {$ctx2.fillBlock({methodSourceCode:methodSourceCode},$ctx1,1)})}));
+return self}, function($ctx1) {$ctx1.fill(self,"compile",{},smalltalk.HLGenerationOutput)})},
+args: [],
+source: "compile\x0a\x09sourceCodes do: [ :methodSourceCode |\x0a\x09\x09(targetClass includesSelector: methodSourceCode selector)\x0a\x09\x09\x09ifFalse: [ \x0a\x09\x09\x09\x09targetClass \x0a\x09\x09\x09\x09\x09compile: methodSourceCode sourceCode\x0a\x09\x09\x09\x09\x09protocol: protocol ] ]",
+messageSends: ["do:", "ifFalse:", "includesSelector:", "selector", "compile:protocol:", "sourceCode"],
+referencedClasses: []
+}),
+smalltalk.HLGenerationOutput);
+
 smalltalk.addMethod(
 smalltalk.method({
 selector: "initialize",
@@ -75,29 +98,6 @@ referencedClasses: []
 }),
 smalltalk.HLGenerationOutput);
 
-smalltalk.addMethod(
-smalltalk.method({
-selector: "serialize",
-protocol: 'protocol',
-fn: function (){
-var self=this;
-return smalltalk.withContext(function($ctx1) { 
-var $1;
-_st(self["@sourceCodes"])._do_((function(methodSourceCode){
-return smalltalk.withContext(function($ctx2) {
-$1=_st(self["@targetClass"])._includesSelector_(_st(methodSourceCode)._selector());
-if(! smalltalk.assert($1)){
-return _st(self["@targetClass"])._compile_protocol_(_st(methodSourceCode)._sourceCode(),self["@protocol"]);
-};
-}, function($ctx2) {$ctx2.fillBlock({methodSourceCode:methodSourceCode},$ctx1,1)})}));
-return self}, function($ctx1) {$ctx1.fill(self,"serialize",{},smalltalk.HLGenerationOutput)})},
-args: [],
-source: "serialize\x0a\x09sourceCodes do: [ :methodSourceCode |\x0a\x09\x09(targetClass includesSelector: methodSourceCode selector)\x0a\x09\x09\x09ifFalse: [ \x0a\x09\x09\x09\x09targetClass \x0a\x09\x09\x09\x09\x09compile: methodSourceCode sourceCode\x0a\x09\x09\x09\x09\x09protocol: protocol ] ]",
-messageSends: ["do:", "ifFalse:", "includesSelector:", "selector", "compile:protocol:", "sourceCode"],
-referencedClasses: []
-}),
-smalltalk.HLGenerationOutput);
-
 smalltalk.addMethod(
 smalltalk.method({
 selector: "sourceCodes",
@@ -226,7 +226,7 @@ smalltalk.HLGenerator);
 
 smalltalk.addMethod(
 smalltalk.method({
-selector: "compile",
+selector: "generate",
 protocol: 'protocol',
 fn: function (){
 var self=this;
@@ -238,9 +238,9 @@ self._error_("class should not be nil");
 } else {
 $1;
 };
-return self}, function($ctx1) {$ctx1.fill(self,"compile",{},smalltalk.HLGenerator)})},
+return self}, function($ctx1) {$ctx1.fill(self,"generate",{},smalltalk.HLGenerator)})},
 args: [],
-source: "compile\x0a\x0a\x09output targetClass ifNil: [ self error: 'class should not be nil'].",
+source: "generate\x0a\x09output targetClass ifNil: [ self error: 'class should not be nil'].",
 messageSends: ["ifNil:", "targetClass", "error:"],
 referencedClasses: []
 }),
@@ -332,20 +332,20 @@ smalltalk.HLAccessorsGenerator);
 
 smalltalk.addMethod(
 smalltalk.method({
-selector: "compile",
+selector: "generate",
 protocol: 'protocol',
 fn: function (){
 var self=this;
 return smalltalk.withContext(function($ctx1) { 
 var $1,$2;
-smalltalk.HLAccessorsGenerator.superclass.fn.prototype._compile.apply(_st(self), []);
+smalltalk.HLAccessorsGenerator.superclass.fn.prototype._generate.apply(_st(self), []);
 $1=_st(self["@output"])._targetClass();
 _st($1)._accessorsSourceCodesWith_(self);
 $2=_st($1)._accessorProtocolWith_(self);
-return self}, function($ctx1) {$ctx1.fill(self,"compile",{},smalltalk.HLAccessorsGenerator)})},
+return self}, function($ctx1) {$ctx1.fill(self,"generate",{},smalltalk.HLAccessorsGenerator)})},
 args: [],
-source: "compile\x0a\x09super compile.\x0a\x09\x0a\x09output targetClass \x0a\x09\x09accessorsSourceCodesWith: self;\x0a\x09\x09accessorProtocolWith: self",
-messageSends: ["compile", "accessorsSourceCodesWith:", "targetClass", "accessorProtocolWith:"],
+source: "generate\x0a\x09super generate.\x0a\x09\x0a\x09output targetClass \x0a\x09\x09accessorsSourceCodesWith: self;\x0a\x09\x09accessorProtocolWith: self",
+messageSends: ["generate", "accessorsSourceCodesWith:", "targetClass", "accessorProtocolWith:"],
 referencedClasses: []
 }),
 smalltalk.HLAccessorsGenerator);
@@ -416,27 +416,6 @@ smalltalk.HLAccessorsGenerator);
 
 smalltalk.addClass('HLInitializeGenerator', smalltalk.HLGenerator, [], 'Helios-Helpers');
 smalltalk.HLInitializeGenerator.comment="I am used to double-dispatch the `initialize` method(s) generation.\x0a\x0aUsage:\x0a\x0a    ^ HLInitializeGenerator new\x0a        class: aClass;\x0a        generate;\x0a        output\x0a\x0aI am a disposable object";
-smalltalk.addMethod(
-smalltalk.method({
-selector: "compile",
-protocol: 'protocol',
-fn: function (){
-var self=this;
-return smalltalk.withContext(function($ctx1) { 
-var $1,$2;
-smalltalk.HLInitializeGenerator.superclass.fn.prototype._compile.apply(_st(self), []);
-$1=_st(self["@output"])._targetClass();
-_st($1)._initializeSourceCodesWith_(self);
-_st($1)._initializeIndexWith_(self);
-$2=_st($1)._initializeProtocolWith_(self);
-return self}, function($ctx1) {$ctx1.fill(self,"compile",{},smalltalk.HLInitializeGenerator)})},
-args: [],
-source: "compile\x0a\x09super compile.\x0a\x09\x0a\x09output targetClass \x0a\x09\x09initializeSourceCodesWith: self;\x0a\x09\x09initializeIndexWith: self;\x0a\x09\x09initializeProtocolWith: self",
-messageSends: ["compile", "initializeSourceCodesWith:", "targetClass", "initializeIndexWith:", "initializeProtocolWith:"],
-referencedClasses: []
-}),
-smalltalk.HLInitializeGenerator);
-
 smalltalk.addMethod(
 smalltalk.method({
 selector: "computeIndexForObject",
@@ -466,6 +445,27 @@ referencedClasses: []
 }),
 smalltalk.HLInitializeGenerator);
 
+smalltalk.addMethod(
+smalltalk.method({
+selector: "generate",
+protocol: 'protocol',
+fn: function (){
+var self=this;
+return smalltalk.withContext(function($ctx1) { 
+var $1,$2;
+smalltalk.HLInitializeGenerator.superclass.fn.prototype._generate.apply(_st(self), []);
+$1=_st(self["@output"])._targetClass();
+_st($1)._initializeSourceCodesWith_(self);
+_st($1)._initializeIndexWith_(self);
+$2=_st($1)._initializeProtocolWith_(self);
+return self}, function($ctx1) {$ctx1.fill(self,"generate",{},smalltalk.HLInitializeGenerator)})},
+args: [],
+source: "generate\x0a\x09super generate.\x0a\x09\x0a\x09output targetClass \x0a\x09\x09initializeSourceCodesWith: self;\x0a\x09\x09initializeIndexWith: self;\x0a\x09\x09initializeProtocolWith: self",
+messageSends: ["generate", "initializeSourceCodesWith:", "targetClass", "initializeIndexWith:", "initializeProtocolWith:"],
+referencedClasses: []
+}),
+smalltalk.HLInitializeGenerator);
+
 smalltalk.addMethod(
 smalltalk.method({
 selector: "generateInitializeCodeForObject",

+ 58 - 57
js/Kernel-Collections.js

@@ -2494,6 +2494,32 @@ referencedClasses: []
 }),
 smalltalk.SequenceableCollection);
 
+smalltalk.addMethod(
+smalltalk.method({
+selector: "beginsWith:",
+protocol: 'testing',
+fn: function (prefix){
+var self=this;
+return smalltalk.withContext(function($ctx1) { 
+var $2,$3,$1,$4;
+$2=self._size();
+$ctx1.sendIdx["size"]=1;
+$3=_st(prefix)._size();
+$ctx1.sendIdx["size"]=2;
+$1=_st($2).__lt($3);
+if(smalltalk.assert($1)){
+return false;
+};
+$4=_st(self._first_(_st(prefix)._size())).__eq(prefix);
+return $4;
+}, function($ctx1) {$ctx1.fill(self,"beginsWith:",{prefix:prefix},smalltalk.SequenceableCollection)})},
+args: ["prefix"],
+source: "beginsWith: prefix\x0a\x09self size < prefix size ifTrue: [ ^ false ].\x0a\x09^ (self first: prefix size) = prefix",
+messageSends: ["ifTrue:", "<", "size", "=", "first:"],
+referencedClasses: []
+}),
+smalltalk.SequenceableCollection);
+
 smalltalk.addMethod(
 smalltalk.method({
 selector: "copyFrom:to:",
@@ -2586,6 +2612,32 @@ referencedClasses: []
 }),
 smalltalk.SequenceableCollection);
 
+smalltalk.addMethod(
+smalltalk.method({
+selector: "endsWith:",
+protocol: 'testing',
+fn: function (suffix){
+var self=this;
+return smalltalk.withContext(function($ctx1) { 
+var $2,$3,$1,$4;
+$2=self._size();
+$ctx1.sendIdx["size"]=1;
+$3=_st(suffix)._size();
+$ctx1.sendIdx["size"]=2;
+$1=_st($2).__lt($3);
+if(smalltalk.assert($1)){
+return false;
+};
+$4=_st(self._last_(_st(suffix)._size())).__eq(suffix);
+return $4;
+}, function($ctx1) {$ctx1.fill(self,"endsWith:",{suffix:suffix},smalltalk.SequenceableCollection)})},
+args: ["suffix"],
+source: "endsWith: suffix\x0a\x09self size < suffix size ifTrue: [ ^ false ].\x0a\x09^ (self last: suffix size) = suffix",
+messageSends: ["ifTrue:", "<", "size", "=", "last:"],
+referencedClasses: []
+}),
+smalltalk.SequenceableCollection);
+
 smalltalk.addMethod(
 smalltalk.method({
 selector: "first",
@@ -2755,22 +2807,23 @@ protocol: 'accessing',
 fn: function (aNumber){
 var self=this;
 return smalltalk.withContext(function($ctx1) { 
-var $2,$1,$5,$4,$3;
+var $2,$1,$6,$5,$4,$3;
 $2=self._size();
 $ctx1.sendIdx["size"]=1;
 $1=_st($2).__lt(aNumber);
 if(smalltalk.assert($1)){
 self._error_("Invalid number of elements");
 };
-$5=self._size();
+$6=self._size();
 $ctx1.sendIdx["size"]=2;
-$4=_st($5).__minus(aNumber);
+$5=_st($6).__minus(aNumber);
+$4=_st($5).__plus((1));
 $3=self._copyFrom_to_($4,self._size());
 return $3;
 }, function($ctx1) {$ctx1.fill(self,"last:",{aNumber:aNumber},smalltalk.SequenceableCollection)})},
 args: ["aNumber"],
-source: "last: aNumber\x0a\x09\x22Answer the last aNumber elements of the receiver.\x0a\x09Raise an error if there are not enough elements in the receiver.\x22\x0a\x0a\x09self size < aNumber ifTrue: [ self error: 'Invalid number of elements' ].\x0a\x0a\x09^ self copyFrom: self size - aNumber to: self size",
-messageSends: ["ifTrue:", "<", "size", "error:", "copyFrom:to:", "-"],
+source: "last: aNumber\x0a\x09\x22Answer the last aNumber elements of the receiver.\x0a\x09Raise an error if there are not enough elements in the receiver.\x22\x0a\x0a\x09self size < aNumber ifTrue: [ self error: 'Invalid number of elements' ].\x0a\x0a\x09^ self copyFrom: self size - aNumber + 1 to: self size",
+messageSends: ["ifTrue:", "<", "size", "error:", "copyFrom:to:", "+", "-"],
 referencedClasses: []
 }),
 smalltalk.SequenceableCollection);
@@ -4146,32 +4199,6 @@ referencedClasses: []
 }),
 smalltalk.String);
 
-smalltalk.addMethod(
-smalltalk.method({
-selector: "beginsWith:",
-protocol: 'testing',
-fn: function (prefix){
-var self=this;
-return smalltalk.withContext(function($ctx1) { 
-var $2,$3,$1,$4;
-$2=self._size();
-$ctx1.sendIdx["size"]=1;
-$3=_st(prefix)._size();
-$ctx1.sendIdx["size"]=2;
-$1=_st($2).__lt($3);
-if(smalltalk.assert($1)){
-return false;
-};
-$4=_st(self._first_(_st(prefix)._size())).__eq(prefix);
-return $4;
-}, function($ctx1) {$ctx1.fill(self,"beginsWith:",{prefix:prefix},smalltalk.String)})},
-args: ["prefix"],
-source: "beginsWith: prefix\x0a\x09self size < prefix size ifTrue: [ ^ false ].\x0a\x09^ (self first: prefix size) = prefix",
-messageSends: ["ifTrue:", "<", "size", "=", "first:"],
-referencedClasses: []
-}),
-smalltalk.String);
-
 smalltalk.addMethod(
 smalltalk.method({
 selector: "capitalized",
@@ -4264,32 +4291,6 @@ referencedClasses: []
 }),
 smalltalk.String);
 
-smalltalk.addMethod(
-smalltalk.method({
-selector: "endsWith:",
-protocol: 'testing',
-fn: function (suffix){
-var self=this;
-return smalltalk.withContext(function($ctx1) { 
-var $2,$3,$1,$4;
-$2=self._size();
-$ctx1.sendIdx["size"]=1;
-$3=_st(suffix)._size();
-$ctx1.sendIdx["size"]=2;
-$1=_st($2).__lt($3);
-if(smalltalk.assert($1)){
-return false;
-};
-$4=_st(self._last_(_st(suffix)._size())).__eq(suffix);
-return $4;
-}, function($ctx1) {$ctx1.fill(self,"endsWith:",{suffix:suffix},smalltalk.String)})},
-args: ["suffix"],
-source: "endsWith: suffix\x0a\x09self size < suffix size ifTrue: [ ^ false ].\x0a\x09^ (self last: suffix size) = suffix",
-messageSends: ["ifTrue:", "<", "size", "=", "last:"],
-referencedClasses: []
-}),
-smalltalk.String);
-
 smalltalk.addMethod(
 smalltalk.method({
 selector: "escaped",

+ 67 - 2
js/Kernel-Tests.js

@@ -2737,6 +2737,71 @@ smalltalk.DictionaryTest.klass);
 
 
 smalltalk.addClass('SequenceableCollectionTest', smalltalk.IndexableCollectionTest, [], 'Kernel-Tests');
+smalltalk.addMethod(
+smalltalk.method({
+selector: "testBeginsWith",
+protocol: 'tests',
+fn: function (){
+var self=this;
+return smalltalk.withContext(function($ctx1) { 
+var $2,$4,$3,$1,$6,$5;
+$2=self._collection();
+$ctx1.sendIdx["collection"]=1;
+$4=self._collection();
+$ctx1.sendIdx["collection"]=2;
+$3=_st($4)._first_((3));
+$1=_st($2)._beginsWith_($3);
+$ctx1.sendIdx["beginsWith:"]=1;
+self._assert_($1);
+$6=self._collection();
+$ctx1.sendIdx["collection"]=3;
+$5=_st($6)._beginsWith_(_st(self._collection())._copyFrom_to_((2),(3)));
+self._deny_($5);
+return self}, function($ctx1) {$ctx1.fill(self,"testBeginsWith",{},smalltalk.SequenceableCollectionTest)})},
+args: [],
+source: "testBeginsWith\x0a\x09self assert: (self collection beginsWith: (self collection first: 3)).\x0a\x09self deny: (self collection beginsWith: (self collection copyFrom: 2 to: 3))",
+messageSends: ["assert:", "beginsWith:", "collection", "first:", "deny:", "copyFrom:to:"],
+referencedClasses: []
+}),
+smalltalk.SequenceableCollectionTest);
+
+smalltalk.addMethod(
+smalltalk.method({
+selector: "testEndsWith",
+protocol: 'tests',
+fn: function (){
+var self=this;
+return smalltalk.withContext(function($ctx1) { 
+var $2,$4,$3,$1,$6,$8,$11,$10,$9,$7,$5;
+$2=self._collection();
+$ctx1.sendIdx["collection"]=1;
+$4=self._collection();
+$ctx1.sendIdx["collection"]=2;
+$3=_st($4)._last_((3));
+$1=_st($2)._endsWith_($3);
+$ctx1.sendIdx["endsWith:"]=1;
+self._assert_($1);
+$6=self._collection();
+$ctx1.sendIdx["collection"]=3;
+$8=self._collection();
+$ctx1.sendIdx["collection"]=4;
+$11=self._collection();
+$ctx1.sendIdx["collection"]=5;
+$10=_st($11)._size();
+$ctx1.sendIdx["size"]=1;
+$9=_st($10).__minus((3));
+$ctx1.sendIdx["-"]=1;
+$7=_st($8)._copyFrom_to_($9,_st(_st(self._collection())._size()).__minus((1)));
+$5=_st($6)._endsWith_($7);
+self._deny_($5);
+return self}, function($ctx1) {$ctx1.fill(self,"testEndsWith",{},smalltalk.SequenceableCollectionTest)})},
+args: [],
+source: "testEndsWith\x0a\x09self assert: (self collection endsWith: (self collection last: 3)).\x0a\x09self deny: (self collection endsWith: (self collection copyFrom: self collection size - 3 to: self collection size - 1))",
+messageSends: ["assert:", "endsWith:", "collection", "last:", "deny:", "copyFrom:to:", "-", "size"],
+referencedClasses: []
+}),
+smalltalk.SequenceableCollectionTest);
+
 smalltalk.addMethod(
 smalltalk.method({
 selector: "testFirst",
@@ -2848,7 +2913,7 @@ $7=self._collection();
 $ctx1.sendIdx["collection"]=3;
 $6=_st($7)._size();
 $ctx1.sendIdx["size"]=1;
-$5=_st($6).__minus((2));
+$5=_st($6).__minus((1));
 $9=self._collection();
 $ctx1.sendIdx["collection"]=4;
 $8=_st($9)._size();
@@ -2860,7 +2925,7 @@ return _st(self._collection())._last_((33));
 }, function($ctx2) {$ctx2.fillBlock({},$ctx1,1)})}),$Error());
 return self}, function($ctx1) {$ctx1.fill(self,"testLastN",{},smalltalk.SequenceableCollectionTest)})},
 args: [],
-source: "testLastN\x0a\x09self \x0a\x09\x09assert: (self collection last: 2) \x0a\x09\x09equals: (self collection copyFrom: self collection size -2 to: self collection size).\x0a\x09\x09\x0a\x09self should: [ self collection last: 33 ] raise: Error",
+source: "testLastN\x0a\x09self \x0a\x09\x09assert: (self collection last: 2) \x0a\x09\x09equals: (self collection copyFrom: self collection size -1 to: self collection size).\x0a\x09\x09\x0a\x09self should: [ self collection last: 33 ] raise: Error",
 messageSends: ["assert:equals:", "last:", "collection", "copyFrom:to:", "-", "size", "should:raise:"],
 referencedClasses: ["Error"]
 }),

+ 6 - 7
st/Helios-Helpers.st

@@ -49,7 +49,7 @@ addSourceCode: aString
 	sourceCodes add: aString
 !
 
-serialize
+compile
 	sourceCodes do: [ :methodSourceCode |
 		(targetClass includesSelector: methodSourceCode selector)
 			ifFalse: [ 
@@ -104,8 +104,7 @@ initialize
 
 !HLGenerator methodsFor: 'protocol'!
 
-compile
-
+generate
 	output targetClass ifNil: [ self error: 'class should not be nil'].
 ! !
 
@@ -154,8 +153,8 @@ setterFor: anInstanceVariable
 
 !HLAccessorsGenerator methodsFor: 'protocol'!
 
-compile
-	super compile.
+generate
+	super generate.
 	
 	output targetClass 
 		accessorsSourceCodesWith: self;
@@ -239,8 +238,8 @@ retrieveProtocolForObject
 
 !HLInitializeGenerator methodsFor: 'protocol'!
 
-compile
-	super compile.
+generate
+	super generate.
 	
 	output targetClass 
 		initializeSourceCodesWith: self;

+ 11 - 11
st/Kernel-Collections.st

@@ -871,7 +871,7 @@ last: aNumber
 
 	self size < aNumber ifTrue: [ self error: 'Invalid number of elements' ].
 
-	^ self copyFrom: self size - aNumber to: self size
+	^ self copyFrom: self size - aNumber + 1 to: self size
 !
 
 second
@@ -1017,6 +1017,16 @@ writeStream
 
 !SequenceableCollection methodsFor: 'testing'!
 
+beginsWith: prefix
+	self size < prefix size ifTrue: [ ^ false ].
+	^ (self first: prefix size) = prefix
+!
+
+endsWith: suffix
+	self size < suffix size ifTrue: [ ^ false ].
+	^ (self last: suffix size) = suffix
+!
+
 includes: anObject
 	^ (self indexOf: anObject ifAbsent: [ nil ]) notNil
 ! !
@@ -1611,16 +1621,6 @@ tokenize: aString
 
 !String methodsFor: 'testing'!
 
-beginsWith: prefix
-	self size < prefix size ifTrue: [ ^ false ].
-	^ (self first: prefix size) = prefix
-!
-
-endsWith: suffix
-	self size < suffix size ifTrue: [ ^ false ].
-	^ (self last: suffix size) = suffix
-!
-
 includesSubString: subString
 	< return self.indexOf(subString) !!= -1 >
 !

+ 11 - 1
st/Kernel-Tests.st

@@ -842,6 +842,16 @@ IndexableCollectionTest subclass: #SequenceableCollectionTest
 
 !SequenceableCollectionTest methodsFor: 'tests'!
 
+testBeginsWith
+	self assert: (self collection beginsWith: (self collection first: 3)).
+	self deny: (self collection beginsWith: (self collection copyFrom: 2 to: 3))
+!
+
+testEndsWith
+	self assert: (self collection endsWith: (self collection last: 3)).
+	self deny: (self collection endsWith: (self collection copyFrom: self collection size - 3 to: self collection size - 1))
+!
+
 testFirst
 	self assert: (self collection first) equals: (self collection at: 1)
 !
@@ -865,7 +875,7 @@ testLast
 testLastN
 	self 
 		assert: (self collection last: 2) 
-		equals: (self collection copyFrom: self collection size -2 to: self collection size).
+		equals: (self collection copyFrom: self collection size -1 to: self collection size).
 		
 	self should: [ self collection last: 33 ] raise: Error
 !