|
@@ -8679,322 +8679,474 @@ $globals.Set);
|
|
|
|
|
|
|
|
|
|
|
|
-$core.addClass('Queue', $globals.Object, ['read', 'readIndex', 'write'], 'Kernel-Collections');
|
|
|
+$core.addClass('ProtoStream', $globals.Object, [], 'Kernel-Collections');
|
|
|
|
|
|
-$globals.Queue.comment="I am a one-sided queue.\x0a\x0a## Usage\x0a\x0aUse `#nextPut:` to add items to the queue.\x0aUse `#next` or `#nextIfAbsent:` to get (and remove) the next item in the queue.\x0a\x0a## Implementation notes\x0a\x0aA Queue uses two OrderedCollections inside,\x0a`read` is at the front, is not modified and only read using `readIndex`.\x0a`write` is at the back and is appended new items.\x0aWhen `read` is exhausted, `write` is promoted to `read` and new `write` is created.\x0a\x0aAs a consequence, no data moving is done by me, write appending may do data moving\x0awhen growing `write`, but this is left to engine to implement as good as it chooses to.";
|
|
|
+$globals.ProtoStream.comment="I am the abstract base for different accessor for a sequence of objects. This sequence is referred to as my \x22contents\x22.\x0aMy instances are read/write streams modifying the contents.";
|
|
|
|
|
|
$core.addMethod(
|
|
|
$core.method({
|
|
|
-selector: "initialize",
|
|
|
-protocol: 'initialization',
|
|
|
-fn: function (){
|
|
|
+selector: "<<",
|
|
|
+protocol: 'writing',
|
|
|
+fn: function (anObject){
|
|
|
var self=this;
|
|
|
-function $OrderedCollection(){return $globals.OrderedCollection||(typeof OrderedCollection=="undefined"?nil:OrderedCollection)}
|
|
|
|
|
|
return $core.withContext(function($ctx1) {
|
|
|
|
|
|
-(
|
|
|
+self._write_(anObject);
|
|
|
+return self;
|
|
|
|
|
|
-$ctx1.supercall = true,
|
|
|
+}, function($ctx1) {$ctx1.fill(self,"<<",{anObject:anObject},$globals.ProtoStream)});
|
|
|
|
|
|
-$globals.Queue.superclass.fn.prototype._initialize.apply($recv(self), []));
|
|
|
-
|
|
|
-$ctx1.supercall = false;
|
|
|
-
|
|
|
-self["@read"]=$recv($OrderedCollection())._new();
|
|
|
+},
|
|
|
+
|
|
|
+args: ["anObject"],
|
|
|
+source: "<< anObject\x0a\x09self write: anObject",
|
|
|
+referencedClasses: [],
|
|
|
+
|
|
|
+messageSends: ["write:"]
|
|
|
+}),
|
|
|
+$globals.ProtoStream);
|
|
|
+
|
|
|
+$core.addMethod(
|
|
|
+$core.method({
|
|
|
+selector: "atEnd",
|
|
|
+protocol: 'testing',
|
|
|
+fn: function (){
|
|
|
+var self=this;
|
|
|
|
|
|
-$ctx1.sendIdx["new"]=1;
|
|
|
+return $core.withContext(function($ctx1) {
|
|
|
|
|
|
-self["@write"]=$recv($OrderedCollection())._new();
|
|
|
-self["@readIndex"]=(1);
|
|
|
+self._subclassResponsibility();
|
|
|
return self;
|
|
|
|
|
|
-}, function($ctx1) {$ctx1.fill(self,"initialize",{},$globals.Queue)});
|
|
|
+}, function($ctx1) {$ctx1.fill(self,"atEnd",{},$globals.ProtoStream)});
|
|
|
|
|
|
},
|
|
|
|
|
|
args: [],
|
|
|
-source: "initialize\x0a\x09super initialize.\x0a\x09read := OrderedCollection new.\x0a\x09write := OrderedCollection new.\x0a\x09readIndex := 1",
|
|
|
-referencedClasses: ["OrderedCollection"],
|
|
|
+source: "atEnd\x0a\x09self subclassResponsibility",
|
|
|
+referencedClasses: [],
|
|
|
|
|
|
-messageSends: ["initialize", "new"]
|
|
|
+messageSends: ["subclassResponsibility"]
|
|
|
}),
|
|
|
-$globals.Queue);
|
|
|
+$globals.ProtoStream);
|
|
|
|
|
|
$core.addMethod(
|
|
|
$core.method({
|
|
|
-selector: "next",
|
|
|
-protocol: 'accessing',
|
|
|
+selector: "atStart",
|
|
|
+protocol: 'testing',
|
|
|
fn: function (){
|
|
|
var self=this;
|
|
|
|
|
|
return $core.withContext(function($ctx1) {
|
|
|
|
|
|
-var $1;
|
|
|
-$1=self._nextIfAbsent_((function(){
|
|
|
+self._subclassResponsibility();
|
|
|
+return self;
|
|
|
|
|
|
-return $core.withContext(function($ctx2) {
|
|
|
+}, function($ctx1) {$ctx1.fill(self,"atStart",{},$globals.ProtoStream)});
|
|
|
|
|
|
-return self._error_("Cannot read from empty Queue.");
|
|
|
+},
|
|
|
+
|
|
|
+args: [],
|
|
|
+source: "atStart\x0a\x09self subclassResponsibility",
|
|
|
+referencedClasses: [],
|
|
|
+
|
|
|
+messageSends: ["subclassResponsibility"]
|
|
|
+}),
|
|
|
+$globals.ProtoStream);
|
|
|
+
|
|
|
+$core.addMethod(
|
|
|
+$core.method({
|
|
|
+selector: "contents",
|
|
|
+protocol: 'accessing',
|
|
|
+fn: function (){
|
|
|
+var self=this;
|
|
|
|
|
|
-}, function($ctx2) {$ctx2.fillBlock({},$ctx1,1)});
|
|
|
+return $core.withContext(function($ctx1) {
|
|
|
|
|
|
-}));
|
|
|
-return $1;
|
|
|
+self._subclassResponsibility();
|
|
|
+return self;
|
|
|
|
|
|
-}, function($ctx1) {$ctx1.fill(self,"next",{},$globals.Queue)});
|
|
|
+}, function($ctx1) {$ctx1.fill(self,"contents",{},$globals.ProtoStream)});
|
|
|
|
|
|
},
|
|
|
|
|
|
args: [],
|
|
|
-source: "next\x0a\x09^ self nextIfAbsent: [ self error: 'Cannot read from empty Queue.' ]",
|
|
|
+source: "contents\x0a\x09self subclassResponsibility",
|
|
|
referencedClasses: [],
|
|
|
|
|
|
-messageSends: ["nextIfAbsent:", "error:"]
|
|
|
+messageSends: ["subclassResponsibility"]
|
|
|
}),
|
|
|
-$globals.Queue);
|
|
|
+$globals.ProtoStream);
|
|
|
|
|
|
$core.addMethod(
|
|
|
$core.method({
|
|
|
-selector: "nextIfAbsent:",
|
|
|
-protocol: 'accessing',
|
|
|
+selector: "do:",
|
|
|
+protocol: 'enumerating',
|
|
|
fn: function (aBlock){
|
|
|
var self=this;
|
|
|
-var result;
|
|
|
-function $OrderedCollection(){return $globals.OrderedCollection||(typeof OrderedCollection=="undefined"?nil:OrderedCollection)}
|
|
|
|
|
|
return $core.withContext(function($ctx1) {
|
|
|
|
|
|
-var $1,$2,$3,$4;
|
|
|
-var $early={};
|
|
|
-try {
|
|
|
-result=$recv(self["@read"])._at_ifAbsent_(self["@readIndex"],(function(){
|
|
|
+$recv((function(){
|
|
|
|
|
|
return $core.withContext(function($ctx2) {
|
|
|
|
|
|
-$1=$recv(self["@write"])._isEmpty();
|
|
|
-if($core.assert($1)){
|
|
|
-$2=$recv(self["@readIndex"]).__gt((1));
|
|
|
-if($core.assert($2)){
|
|
|
-self["@read"]=[];
|
|
|
-self["@read"];
|
|
|
-self["@readIndex"]=(1);
|
|
|
-self["@readIndex"];
|
|
|
-};
|
|
|
-$3=$recv(aBlock)._value();
|
|
|
-throw $early=[$3];
|
|
|
-};
|
|
|
-self["@read"]=self["@write"];
|
|
|
-self["@read"];
|
|
|
-self["@readIndex"]=(1);
|
|
|
-self["@readIndex"];
|
|
|
-self["@write"]=$recv($OrderedCollection())._new();
|
|
|
-self["@write"];
|
|
|
-return $recv(self["@read"])._first();
|
|
|
+return self._atEnd();
|
|
|
|
|
|
}, function($ctx2) {$ctx2.fillBlock({},$ctx1,1)});
|
|
|
|
|
|
+}))._whileFalse_((function(){
|
|
|
+
|
|
|
+return $core.withContext(function($ctx2) {
|
|
|
+
|
|
|
+return $recv(aBlock)._value_(self._next());
|
|
|
+
|
|
|
+}, function($ctx2) {$ctx2.fillBlock({},$ctx1,2)});
|
|
|
+
|
|
|
}));
|
|
|
-$recv(self["@read"])._at_put_(self["@readIndex"],nil);
|
|
|
-self["@readIndex"]=$recv(self["@readIndex"]).__plus((1));
|
|
|
-$4=result;
|
|
|
-return $4;
|
|
|
-}
|
|
|
-catch(e) {if(e===$early)return e[0]; throw e}
|
|
|
+return self;
|
|
|
|
|
|
-}, function($ctx1) {$ctx1.fill(self,"nextIfAbsent:",{aBlock:aBlock,result:result},$globals.Queue)});
|
|
|
+}, function($ctx1) {$ctx1.fill(self,"do:",{aBlock:aBlock},$globals.ProtoStream)});
|
|
|
|
|
|
},
|
|
|
|
|
|
args: ["aBlock"],
|
|
|
-source: "nextIfAbsent: aBlock\x0a\x09| result |\x0a\x09result := read at: readIndex ifAbsent: [\x0a\x09\x09write isEmpty ifTrue: [\x0a\x09\x09\x09readIndex > 1 ifTrue: [ read := #(). readIndex := 1 ].\x0a\x09\x09\x09^ aBlock value ].\x0a\x09\x09read := write.\x0a\x09\x09readIndex := 1.\x0a\x09\x09write := OrderedCollection new.\x0a\x09\x09read first ].\x0a\x09read at: readIndex put: nil.\x0a\x09readIndex := readIndex + 1.\x0a\x09^ result",
|
|
|
-referencedClasses: ["OrderedCollection"],
|
|
|
+source: "do: aBlock\x0a\x09[ self atEnd ] whileFalse: [ aBlock value: self next ]",
|
|
|
+referencedClasses: [],
|
|
|
|
|
|
-messageSends: ["at:ifAbsent:", "ifTrue:", "isEmpty", ">", "value", "new", "first", "at:put:", "+"]
|
|
|
+messageSends: ["whileFalse:", "atEnd", "value:", "next"]
|
|
|
}),
|
|
|
-$globals.Queue);
|
|
|
+$globals.ProtoStream);
|
|
|
|
|
|
$core.addMethod(
|
|
|
$core.method({
|
|
|
-selector: "nextPut:",
|
|
|
-protocol: 'accessing',
|
|
|
-fn: function (anObject){
|
|
|
+selector: "isEmpty",
|
|
|
+protocol: 'testing',
|
|
|
+fn: function (){
|
|
|
var self=this;
|
|
|
|
|
|
return $core.withContext(function($ctx1) {
|
|
|
|
|
|
-$recv(self["@write"])._add_(anObject);
|
|
|
-return self;
|
|
|
+var $1;
|
|
|
+$1=$recv(self._atStart())._and_((function(){
|
|
|
|
|
|
-}, function($ctx1) {$ctx1.fill(self,"nextPut:",{anObject:anObject},$globals.Queue)});
|
|
|
+return $core.withContext(function($ctx2) {
|
|
|
+
|
|
|
+return self._atEnd();
|
|
|
+
|
|
|
+}, function($ctx2) {$ctx2.fillBlock({},$ctx1,1)});
|
|
|
+
|
|
|
+}));
|
|
|
+return $1;
|
|
|
+
|
|
|
+}, function($ctx1) {$ctx1.fill(self,"isEmpty",{},$globals.ProtoStream)});
|
|
|
|
|
|
},
|
|
|
|
|
|
-args: ["anObject"],
|
|
|
-source: "nextPut: anObject\x0a\x09write add: anObject",
|
|
|
+args: [],
|
|
|
+source: "isEmpty\x0a\x09^ self atStart and: [ self atEnd ]",
|
|
|
referencedClasses: [],
|
|
|
|
|
|
-messageSends: ["add:"]
|
|
|
+messageSends: ["and:", "atStart", "atEnd"]
|
|
|
}),
|
|
|
-$globals.Queue);
|
|
|
-
|
|
|
-
|
|
|
+$globals.ProtoStream);
|
|
|
|
|
|
-$core.addClass('RegularExpression', $globals.Object, [], 'Kernel-Collections');
|
|
|
-
|
|
|
-$globals.RegularExpression.comment="I represent a regular expression object. My instances are JavaScript `RegExp` object.";
|
|
|
-
|
|
|
$core.addMethod(
|
|
|
$core.method({
|
|
|
-selector: "compile:",
|
|
|
-protocol: 'evaluating',
|
|
|
-fn: function (aString){
|
|
|
+selector: "next",
|
|
|
+protocol: 'reading',
|
|
|
+fn: function (){
|
|
|
var self=this;
|
|
|
|
|
|
return $core.withContext(function($ctx1) {
|
|
|
|
|
|
-return self.compile(aString);
|
|
|
-return self;
|
|
|
+var $2,$1;
|
|
|
+$2=self._atEnd();
|
|
|
+if($core.assert($2)){
|
|
|
+$1=nil;
|
|
|
+} else {
|
|
|
+$1=self._subclassResponsibility();
|
|
|
+};
|
|
|
+return $1;
|
|
|
|
|
|
-}, function($ctx1) {$ctx1.fill(self,"compile:",{aString:aString},$globals.RegularExpression)});
|
|
|
+}, function($ctx1) {$ctx1.fill(self,"next",{},$globals.ProtoStream)});
|
|
|
|
|
|
},
|
|
|
|
|
|
-args: ["aString"],
|
|
|
-source: "compile: aString\x0a\x09<return self.compile(aString)>",
|
|
|
+args: [],
|
|
|
+source: "next\x0a\x09^ self atEnd\x0a\x09\x09ifTrue: [ nil ]\x0a\x09\x09ifFalse: [ self subclassResponsibility ]",
|
|
|
referencedClasses: [],
|
|
|
|
|
|
-messageSends: []
|
|
|
+messageSends: ["ifTrue:ifFalse:", "atEnd", "subclassResponsibility"]
|
|
|
}),
|
|
|
-$globals.RegularExpression);
|
|
|
+$globals.ProtoStream);
|
|
|
|
|
|
$core.addMethod(
|
|
|
$core.method({
|
|
|
-selector: "exec:",
|
|
|
-protocol: 'evaluating',
|
|
|
-fn: function (aString){
|
|
|
+selector: "nextPut:",
|
|
|
+protocol: 'writing',
|
|
|
+fn: function (anObject){
|
|
|
var self=this;
|
|
|
|
|
|
return $core.withContext(function($ctx1) {
|
|
|
|
|
|
-return self.exec(aString) || nil;
|
|
|
+self._subclassResponsibility();
|
|
|
return self;
|
|
|
|
|
|
-}, function($ctx1) {$ctx1.fill(self,"exec:",{aString:aString},$globals.RegularExpression)});
|
|
|
+}, function($ctx1) {$ctx1.fill(self,"nextPut:",{anObject:anObject},$globals.ProtoStream)});
|
|
|
|
|
|
},
|
|
|
|
|
|
-args: ["aString"],
|
|
|
-source: "exec: aString\x0a\x09<return self.exec(aString) || nil>",
|
|
|
+args: ["anObject"],
|
|
|
+source: "nextPut: anObject\x0a\x09self subclassResponsibility",
|
|
|
referencedClasses: [],
|
|
|
|
|
|
-messageSends: []
|
|
|
+messageSends: ["subclassResponsibility"]
|
|
|
}),
|
|
|
-$globals.RegularExpression);
|
|
|
+$globals.ProtoStream);
|
|
|
|
|
|
$core.addMethod(
|
|
|
$core.method({
|
|
|
-selector: "test:",
|
|
|
-protocol: 'evaluating',
|
|
|
-fn: function (aString){
|
|
|
+selector: "nextPutAll:",
|
|
|
+protocol: 'writing',
|
|
|
+fn: function (aCollection){
|
|
|
var self=this;
|
|
|
|
|
|
return $core.withContext(function($ctx1) {
|
|
|
|
|
|
-return self.test(aString);
|
|
|
+$recv(aCollection)._do_((function(each){
|
|
|
+
|
|
|
+return $core.withContext(function($ctx2) {
|
|
|
+
|
|
|
+return self._nextPut_(each);
|
|
|
+
|
|
|
+}, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1,1)});
|
|
|
+
|
|
|
+}));
|
|
|
return self;
|
|
|
|
|
|
-}, function($ctx1) {$ctx1.fill(self,"test:",{aString:aString},$globals.RegularExpression)});
|
|
|
+}, function($ctx1) {$ctx1.fill(self,"nextPutAll:",{aCollection:aCollection},$globals.ProtoStream)});
|
|
|
|
|
|
},
|
|
|
|
|
|
-args: ["aString"],
|
|
|
-source: "test: aString\x0a\x09<return self.test(aString)>",
|
|
|
+args: ["aCollection"],
|
|
|
+source: "nextPutAll: aCollection\x0a\x09aCollection do: [ :each |\x0a\x09\x09self nextPut: each ]",
|
|
|
referencedClasses: [],
|
|
|
|
|
|
-messageSends: []
|
|
|
+messageSends: ["do:", "nextPut:"]
|
|
|
}),
|
|
|
-$globals.RegularExpression);
|
|
|
-
|
|
|
+$globals.ProtoStream);
|
|
|
|
|
|
$core.addMethod(
|
|
|
$core.method({
|
|
|
-selector: "fromString:",
|
|
|
-protocol: 'instance creation',
|
|
|
+selector: "nextPutString:",
|
|
|
+protocol: 'writing',
|
|
|
fn: function (aString){
|
|
|
var self=this;
|
|
|
|
|
|
return $core.withContext(function($ctx1) {
|
|
|
|
|
|
-var $1;
|
|
|
-$1=self._fromString_flag_(aString,"");
|
|
|
-return $1;
|
|
|
+self._nextPut_(aString);
|
|
|
+return self;
|
|
|
|
|
|
-}, function($ctx1) {$ctx1.fill(self,"fromString:",{aString:aString},$globals.RegularExpression.klass)});
|
|
|
+}, function($ctx1) {$ctx1.fill(self,"nextPutString:",{aString:aString},$globals.ProtoStream)});
|
|
|
|
|
|
},
|
|
|
|
|
|
args: ["aString"],
|
|
|
-source: "fromString: aString\x0a\x09\x09^ self fromString: aString flag: ''",
|
|
|
+source: "nextPutString: aString\x0a\x09self nextPut: aString",
|
|
|
referencedClasses: [],
|
|
|
|
|
|
-messageSends: ["fromString:flag:"]
|
|
|
+messageSends: ["nextPut:"]
|
|
|
}),
|
|
|
-$globals.RegularExpression.klass);
|
|
|
+$globals.ProtoStream);
|
|
|
|
|
|
$core.addMethod(
|
|
|
$core.method({
|
|
|
-selector: "fromString:flag:",
|
|
|
-protocol: 'instance creation',
|
|
|
-fn: function (aString,anotherString){
|
|
|
+selector: "peek",
|
|
|
+protocol: 'reading',
|
|
|
+fn: function (){
|
|
|
var self=this;
|
|
|
|
|
|
return $core.withContext(function($ctx1) {
|
|
|
|
|
|
-return new RegExp(aString, anotherString);
|
|
|
-return self;
|
|
|
-
|
|
|
-}, function($ctx1) {$ctx1.fill(self,"fromString:flag:",{aString:aString,anotherString:anotherString},$globals.RegularExpression.klass)});
|
|
|
-
|
|
|
-},
|
|
|
-
|
|
|
-args: ["aString", "anotherString"],
|
|
|
-source: "fromString: aString flag: anotherString\x0a\x09<return new RegExp(aString, anotherString)>",
|
|
|
+var $2,$1;
|
|
|
+$2=self._atEnd();
|
|
|
+if($core.assert($2)){
|
|
|
+$1=nil;
|
|
|
+} else {
|
|
|
+$1=self._subclassResponsibility();
|
|
|
+};
|
|
|
+return $1;
|
|
|
+
|
|
|
+}, function($ctx1) {$ctx1.fill(self,"peek",{},$globals.ProtoStream)});
|
|
|
+
|
|
|
+},
|
|
|
+
|
|
|
+args: [],
|
|
|
+source: "peek\x0a\x09^ self atEnd\x0a\x09\x09ifTrue: [ nil ]\x0a\x09\x09ifFalse: [ self subclassResponsibility ]",
|
|
|
referencedClasses: [],
|
|
|
|
|
|
-messageSends: []
|
|
|
+messageSends: ["ifTrue:ifFalse:", "atEnd", "subclassResponsibility"]
|
|
|
}),
|
|
|
-$globals.RegularExpression.klass);
|
|
|
+$globals.ProtoStream);
|
|
|
|
|
|
+$core.addMethod(
|
|
|
+$core.method({
|
|
|
+selector: "reset",
|
|
|
+protocol: 'actions',
|
|
|
+fn: function (){
|
|
|
+var self=this;
|
|
|
+
|
|
|
+return $core.withContext(function($ctx1) {
|
|
|
+
|
|
|
+self._subclassResponsibility();
|
|
|
+return self;
|
|
|
+
|
|
|
+}, function($ctx1) {$ctx1.fill(self,"reset",{},$globals.ProtoStream)});
|
|
|
+
|
|
|
+},
|
|
|
+
|
|
|
+args: [],
|
|
|
+source: "reset\x0a\x09self subclassResponsibility",
|
|
|
+referencedClasses: [],
|
|
|
+
|
|
|
+messageSends: ["subclassResponsibility"]
|
|
|
+}),
|
|
|
+$globals.ProtoStream);
|
|
|
|
|
|
-$core.addClass('Stream', $globals.Object, ['collection', 'position', 'streamSize'], 'Kernel-Collections');
|
|
|
+$core.addMethod(
|
|
|
+$core.method({
|
|
|
+selector: "resetContents",
|
|
|
+protocol: 'actions',
|
|
|
+fn: function (){
|
|
|
+var self=this;
|
|
|
+
|
|
|
+return $core.withContext(function($ctx1) {
|
|
|
+
|
|
|
+self._subclassResponsibility();
|
|
|
+return self;
|
|
|
+
|
|
|
+}, function($ctx1) {$ctx1.fill(self,"resetContents",{},$globals.ProtoStream)});
|
|
|
+
|
|
|
+},
|
|
|
|
|
|
-$globals.Stream.comment="I represent an accessor for a sequence of objects. This sequence is referred to as my \x22contents\x22.\x0aMy instances are read/write streams to the contents sequence collection.";
|
|
|
+args: [],
|
|
|
+source: "resetContents\x0a\x09self subclassResponsibility",
|
|
|
+referencedClasses: [],
|
|
|
|
|
|
+messageSends: ["subclassResponsibility"]
|
|
|
+}),
|
|
|
+$globals.ProtoStream);
|
|
|
+
|
|
|
$core.addMethod(
|
|
|
$core.method({
|
|
|
-selector: "<<",
|
|
|
+selector: "setToEnd",
|
|
|
+protocol: 'positioning',
|
|
|
+fn: function (){
|
|
|
+var self=this;
|
|
|
+
|
|
|
+return $core.withContext(function($ctx1) {
|
|
|
+
|
|
|
+self._subclassResponsibility();
|
|
|
+return self;
|
|
|
+
|
|
|
+}, function($ctx1) {$ctx1.fill(self,"setToEnd",{},$globals.ProtoStream)});
|
|
|
+
|
|
|
+},
|
|
|
+
|
|
|
+args: [],
|
|
|
+source: "setToEnd\x0a\x09self subclassResponsibility",
|
|
|
+referencedClasses: [],
|
|
|
+
|
|
|
+messageSends: ["subclassResponsibility"]
|
|
|
+}),
|
|
|
+$globals.ProtoStream);
|
|
|
+
|
|
|
+$core.addMethod(
|
|
|
+$core.method({
|
|
|
+selector: "setToStart",
|
|
|
+protocol: 'positioning',
|
|
|
+fn: function (){
|
|
|
+var self=this;
|
|
|
+
|
|
|
+return $core.withContext(function($ctx1) {
|
|
|
+
|
|
|
+self._reset();
|
|
|
+return self;
|
|
|
+
|
|
|
+}, function($ctx1) {$ctx1.fill(self,"setToStart",{},$globals.ProtoStream)});
|
|
|
+
|
|
|
+},
|
|
|
+
|
|
|
+args: [],
|
|
|
+source: "setToStart\x0a\x09self reset",
|
|
|
+referencedClasses: [],
|
|
|
+
|
|
|
+messageSends: ["reset"]
|
|
|
+}),
|
|
|
+$globals.ProtoStream);
|
|
|
+
|
|
|
+$core.addMethod(
|
|
|
+$core.method({
|
|
|
+selector: "write:",
|
|
|
protocol: 'writing',
|
|
|
fn: function (anObject){
|
|
|
var self=this;
|
|
|
|
|
|
return $core.withContext(function($ctx1) {
|
|
|
|
|
|
-self._write_(anObject);
|
|
|
+$recv(anObject)._putOn_(self);
|
|
|
return self;
|
|
|
|
|
|
-}, function($ctx1) {$ctx1.fill(self,"<<",{anObject:anObject},$globals.Stream)});
|
|
|
+}, function($ctx1) {$ctx1.fill(self,"write:",{anObject:anObject},$globals.ProtoStream)});
|
|
|
|
|
|
},
|
|
|
|
|
|
args: ["anObject"],
|
|
|
-source: "<< anObject\x0a\x09self write: anObject",
|
|
|
+source: "write: anObject\x0a\x09anObject putOn: self",
|
|
|
referencedClasses: [],
|
|
|
|
|
|
-messageSends: ["write:"]
|
|
|
+messageSends: ["putOn:"]
|
|
|
}),
|
|
|
-$globals.Stream);
|
|
|
+$globals.ProtoStream);
|
|
|
+
|
|
|
+
|
|
|
+$core.addMethod(
|
|
|
+$core.method({
|
|
|
+selector: "on:",
|
|
|
+protocol: 'instance creation',
|
|
|
+fn: function (aCollection){
|
|
|
+var self=this;
|
|
|
+
|
|
|
+return $core.withContext(function($ctx1) {
|
|
|
+
|
|
|
+var $2,$3,$1;
|
|
|
+$2=self._new();
|
|
|
+$recv($2)._setCollection_(aCollection);
|
|
|
+$recv($2)._setStreamSize_($recv(aCollection)._size());
|
|
|
+$3=$recv($2)._yourself();
|
|
|
+$1=$3;
|
|
|
+return $1;
|
|
|
+
|
|
|
+}, function($ctx1) {$ctx1.fill(self,"on:",{aCollection:aCollection},$globals.ProtoStream.klass)});
|
|
|
+
|
|
|
+},
|
|
|
+
|
|
|
+args: ["aCollection"],
|
|
|
+source: "on: aCollection\x0a\x09\x09^ self new\x0a\x09\x09setCollection: aCollection;\x0a\x09\x09setStreamSize: aCollection size;\x0a\x09\x09yourself",
|
|
|
+referencedClasses: [],
|
|
|
+
|
|
|
+messageSends: ["setCollection:", "new", "setStreamSize:", "size", "yourself"]
|
|
|
+}),
|
|
|
+$globals.ProtoStream.klass);
|
|
|
|
|
|
+
|
|
|
+$core.addClass('Stream', $globals.ProtoStream, ['collection', 'position', 'streamSize'], 'Kernel-Collections');
|
|
|
+
|
|
|
+$globals.Stream.comment="I represent an accessor for a sequence of objects. This sequence is referred to as my \x22contents\x22.\x0aMy instances are read/write streams to the contents sequence collection.";
|
|
|
+
|
|
|
$core.addMethod(
|
|
|
$core.method({
|
|
|
selector: "atEnd",
|
|
@@ -9108,46 +9260,6 @@ messageSends: ["copyFrom:to:", "collection", "streamSize"]
|
|
|
}),
|
|
|
$globals.Stream);
|
|
|
|
|
|
-$core.addMethod(
|
|
|
-$core.method({
|
|
|
-selector: "do:",
|
|
|
-protocol: 'enumerating',
|
|
|
-fn: function (aBlock){
|
|
|
-var self=this;
|
|
|
-
|
|
|
-return $core.withContext(function($ctx1) {
|
|
|
-
|
|
|
-$recv((function(){
|
|
|
-
|
|
|
-return $core.withContext(function($ctx2) {
|
|
|
-
|
|
|
-return self._atEnd();
|
|
|
-
|
|
|
-}, function($ctx2) {$ctx2.fillBlock({},$ctx1,1)});
|
|
|
-
|
|
|
-}))._whileFalse_((function(){
|
|
|
-
|
|
|
-return $core.withContext(function($ctx2) {
|
|
|
-
|
|
|
-return $recv(aBlock)._value_(self._next());
|
|
|
-
|
|
|
-}, function($ctx2) {$ctx2.fillBlock({},$ctx1,2)});
|
|
|
-
|
|
|
-}));
|
|
|
-return self;
|
|
|
-
|
|
|
-}, function($ctx1) {$ctx1.fill(self,"do:",{aBlock:aBlock},$globals.Stream)});
|
|
|
-
|
|
|
-},
|
|
|
-
|
|
|
-args: ["aBlock"],
|
|
|
-source: "do: aBlock\x0a\x09[ self atEnd ] whileFalse: [ aBlock value: self next ]",
|
|
|
-referencedClasses: [],
|
|
|
-
|
|
|
-messageSends: ["whileFalse:", "atEnd", "value:", "next"]
|
|
|
-}),
|
|
|
-$globals.Stream);
|
|
|
-
|
|
|
$core.addMethod(
|
|
|
$core.method({
|
|
|
selector: "flush",
|
|
@@ -9303,62 +9415,6 @@ messageSends: ["position:", "+", "position", "at:put:", "collection", "setStream
|
|
|
}),
|
|
|
$globals.Stream);
|
|
|
|
|
|
-$core.addMethod(
|
|
|
-$core.method({
|
|
|
-selector: "nextPutAll:",
|
|
|
-protocol: 'writing',
|
|
|
-fn: function (aCollection){
|
|
|
-var self=this;
|
|
|
-
|
|
|
-return $core.withContext(function($ctx1) {
|
|
|
-
|
|
|
-$recv(aCollection)._do_((function(each){
|
|
|
-
|
|
|
-return $core.withContext(function($ctx2) {
|
|
|
-
|
|
|
-return self._nextPut_(each);
|
|
|
-
|
|
|
-}, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1,1)});
|
|
|
-
|
|
|
-}));
|
|
|
-return self;
|
|
|
-
|
|
|
-}, function($ctx1) {$ctx1.fill(self,"nextPutAll:",{aCollection:aCollection},$globals.Stream)});
|
|
|
-
|
|
|
-},
|
|
|
-
|
|
|
-args: ["aCollection"],
|
|
|
-source: "nextPutAll: aCollection\x0a\x09aCollection do: [ :each |\x0a\x09\x09self nextPut: each ]",
|
|
|
-referencedClasses: [],
|
|
|
-
|
|
|
-messageSends: ["do:", "nextPut:"]
|
|
|
-}),
|
|
|
-$globals.Stream);
|
|
|
-
|
|
|
-$core.addMethod(
|
|
|
-$core.method({
|
|
|
-selector: "nextPutString:",
|
|
|
-protocol: 'writing',
|
|
|
-fn: function (aString){
|
|
|
-var self=this;
|
|
|
-
|
|
|
-return $core.withContext(function($ctx1) {
|
|
|
-
|
|
|
-self._nextPut_(aString);
|
|
|
-return self;
|
|
|
-
|
|
|
-}, function($ctx1) {$ctx1.fill(self,"nextPutString:",{aString:aString},$globals.Stream)});
|
|
|
-
|
|
|
-},
|
|
|
-
|
|
|
-args: ["aString"],
|
|
|
-source: "nextPutString: aString\x0a\x09self nextPut: aString",
|
|
|
-referencedClasses: [],
|
|
|
-
|
|
|
-messageSends: ["nextPut:"]
|
|
|
-}),
|
|
|
-$globals.Stream);
|
|
|
-
|
|
|
$core.addMethod(
|
|
|
$core.method({
|
|
|
selector: "peek",
|
|
@@ -9617,30 +9673,6 @@ messageSends: []
|
|
|
}),
|
|
|
$globals.Stream);
|
|
|
|
|
|
-$core.addMethod(
|
|
|
-$core.method({
|
|
|
-selector: "write:",
|
|
|
-protocol: 'writing',
|
|
|
-fn: function (anObject){
|
|
|
-var self=this;
|
|
|
-
|
|
|
-return $core.withContext(function($ctx1) {
|
|
|
-
|
|
|
-$recv(anObject)._putOn_(self);
|
|
|
-return self;
|
|
|
-
|
|
|
-}, function($ctx1) {$ctx1.fill(self,"write:",{anObject:anObject},$globals.Stream)});
|
|
|
-
|
|
|
-},
|
|
|
-
|
|
|
-args: ["anObject"],
|
|
|
-source: "write: anObject\x0a\x09anObject putOn: self",
|
|
|
-referencedClasses: [],
|
|
|
-
|
|
|
-messageSends: ["putOn:"]
|
|
|
-}),
|
|
|
-$globals.Stream);
|
|
|
-
|
|
|
|
|
|
$core.addMethod(
|
|
|
$core.method({
|
|
@@ -9985,4 +10017,292 @@ messageSends: ["nextPutAll:", "tab"]
|
|
|
$globals.StringStream);
|
|
|
|
|
|
|
|
|
+
|
|
|
+$core.addClass('Queue', $globals.Object, ['read', 'readIndex', 'write'], 'Kernel-Collections');
|
|
|
+
|
|
|
+$globals.Queue.comment="I am a one-sided queue.\x0a\x0a## Usage\x0a\x0aUse `#nextPut:` to add items to the queue.\x0aUse `#next` or `#nextIfAbsent:` to get (and remove) the next item in the queue.\x0a\x0a## Implementation notes\x0a\x0aA Queue uses two OrderedCollections inside,\x0a`read` is at the front, is not modified and only read using `readIndex`.\x0a`write` is at the back and is appended new items.\x0aWhen `read` is exhausted, `write` is promoted to `read` and new `write` is created.\x0a\x0aAs a consequence, no data moving is done by me, write appending may do data moving\x0awhen growing `write`, but this is left to engine to implement as good as it chooses to.";
|
|
|
+
|
|
|
+$core.addMethod(
|
|
|
+$core.method({
|
|
|
+selector: "initialize",
|
|
|
+protocol: 'initialization',
|
|
|
+fn: function (){
|
|
|
+var self=this;
|
|
|
+function $OrderedCollection(){return $globals.OrderedCollection||(typeof OrderedCollection=="undefined"?nil:OrderedCollection)}
|
|
|
+
|
|
|
+return $core.withContext(function($ctx1) {
|
|
|
+
|
|
|
+(
|
|
|
+
|
|
|
+$ctx1.supercall = true,
|
|
|
+
|
|
|
+$globals.Queue.superclass.fn.prototype._initialize.apply($recv(self), []));
|
|
|
+
|
|
|
+$ctx1.supercall = false;
|
|
|
+
|
|
|
+self["@read"]=$recv($OrderedCollection())._new();
|
|
|
+
|
|
|
+$ctx1.sendIdx["new"]=1;
|
|
|
+
|
|
|
+self["@write"]=$recv($OrderedCollection())._new();
|
|
|
+self["@readIndex"]=(1);
|
|
|
+return self;
|
|
|
+
|
|
|
+}, function($ctx1) {$ctx1.fill(self,"initialize",{},$globals.Queue)});
|
|
|
+
|
|
|
+},
|
|
|
+
|
|
|
+args: [],
|
|
|
+source: "initialize\x0a\x09super initialize.\x0a\x09read := OrderedCollection new.\x0a\x09write := OrderedCollection new.\x0a\x09readIndex := 1",
|
|
|
+referencedClasses: ["OrderedCollection"],
|
|
|
+
|
|
|
+messageSends: ["initialize", "new"]
|
|
|
+}),
|
|
|
+$globals.Queue);
|
|
|
+
|
|
|
+$core.addMethod(
|
|
|
+$core.method({
|
|
|
+selector: "next",
|
|
|
+protocol: 'accessing',
|
|
|
+fn: function (){
|
|
|
+var self=this;
|
|
|
+
|
|
|
+return $core.withContext(function($ctx1) {
|
|
|
+
|
|
|
+var $1;
|
|
|
+$1=self._nextIfAbsent_((function(){
|
|
|
+
|
|
|
+return $core.withContext(function($ctx2) {
|
|
|
+
|
|
|
+return self._error_("Cannot read from empty Queue.");
|
|
|
+
|
|
|
+}, function($ctx2) {$ctx2.fillBlock({},$ctx1,1)});
|
|
|
+
|
|
|
+}));
|
|
|
+return $1;
|
|
|
+
|
|
|
+}, function($ctx1) {$ctx1.fill(self,"next",{},$globals.Queue)});
|
|
|
+
|
|
|
+},
|
|
|
+
|
|
|
+args: [],
|
|
|
+source: "next\x0a\x09^ self nextIfAbsent: [ self error: 'Cannot read from empty Queue.' ]",
|
|
|
+referencedClasses: [],
|
|
|
+
|
|
|
+messageSends: ["nextIfAbsent:", "error:"]
|
|
|
+}),
|
|
|
+$globals.Queue);
|
|
|
+
|
|
|
+$core.addMethod(
|
|
|
+$core.method({
|
|
|
+selector: "nextIfAbsent:",
|
|
|
+protocol: 'accessing',
|
|
|
+fn: function (aBlock){
|
|
|
+var self=this;
|
|
|
+var result;
|
|
|
+function $OrderedCollection(){return $globals.OrderedCollection||(typeof OrderedCollection=="undefined"?nil:OrderedCollection)}
|
|
|
+
|
|
|
+return $core.withContext(function($ctx1) {
|
|
|
+
|
|
|
+var $1,$2,$3,$4;
|
|
|
+var $early={};
|
|
|
+try {
|
|
|
+result=$recv(self["@read"])._at_ifAbsent_(self["@readIndex"],(function(){
|
|
|
+
|
|
|
+return $core.withContext(function($ctx2) {
|
|
|
+
|
|
|
+$1=$recv(self["@write"])._isEmpty();
|
|
|
+if($core.assert($1)){
|
|
|
+$2=$recv(self["@readIndex"]).__gt((1));
|
|
|
+if($core.assert($2)){
|
|
|
+self["@read"]=[];
|
|
|
+self["@read"];
|
|
|
+self["@readIndex"]=(1);
|
|
|
+self["@readIndex"];
|
|
|
+};
|
|
|
+$3=$recv(aBlock)._value();
|
|
|
+throw $early=[$3];
|
|
|
+};
|
|
|
+self["@read"]=self["@write"];
|
|
|
+self["@read"];
|
|
|
+self["@readIndex"]=(1);
|
|
|
+self["@readIndex"];
|
|
|
+self["@write"]=$recv($OrderedCollection())._new();
|
|
|
+self["@write"];
|
|
|
+return $recv(self["@read"])._first();
|
|
|
+
|
|
|
+}, function($ctx2) {$ctx2.fillBlock({},$ctx1,1)});
|
|
|
+
|
|
|
+}));
|
|
|
+$recv(self["@read"])._at_put_(self["@readIndex"],nil);
|
|
|
+self["@readIndex"]=$recv(self["@readIndex"]).__plus((1));
|
|
|
+$4=result;
|
|
|
+return $4;
|
|
|
+}
|
|
|
+catch(e) {if(e===$early)return e[0]; throw e}
|
|
|
+
|
|
|
+}, function($ctx1) {$ctx1.fill(self,"nextIfAbsent:",{aBlock:aBlock,result:result},$globals.Queue)});
|
|
|
+
|
|
|
+},
|
|
|
+
|
|
|
+args: ["aBlock"],
|
|
|
+source: "nextIfAbsent: aBlock\x0a\x09| result |\x0a\x09result := read at: readIndex ifAbsent: [\x0a\x09\x09write isEmpty ifTrue: [\x0a\x09\x09\x09readIndex > 1 ifTrue: [ read := #(). readIndex := 1 ].\x0a\x09\x09\x09^ aBlock value ].\x0a\x09\x09read := write.\x0a\x09\x09readIndex := 1.\x0a\x09\x09write := OrderedCollection new.\x0a\x09\x09read first ].\x0a\x09read at: readIndex put: nil.\x0a\x09readIndex := readIndex + 1.\x0a\x09^ result",
|
|
|
+referencedClasses: ["OrderedCollection"],
|
|
|
+
|
|
|
+messageSends: ["at:ifAbsent:", "ifTrue:", "isEmpty", ">", "value", "new", "first", "at:put:", "+"]
|
|
|
+}),
|
|
|
+$globals.Queue);
|
|
|
+
|
|
|
+$core.addMethod(
|
|
|
+$core.method({
|
|
|
+selector: "nextPut:",
|
|
|
+protocol: 'accessing',
|
|
|
+fn: function (anObject){
|
|
|
+var self=this;
|
|
|
+
|
|
|
+return $core.withContext(function($ctx1) {
|
|
|
+
|
|
|
+$recv(self["@write"])._add_(anObject);
|
|
|
+return self;
|
|
|
+
|
|
|
+}, function($ctx1) {$ctx1.fill(self,"nextPut:",{anObject:anObject},$globals.Queue)});
|
|
|
+
|
|
|
+},
|
|
|
+
|
|
|
+args: ["anObject"],
|
|
|
+source: "nextPut: anObject\x0a\x09write add: anObject",
|
|
|
+referencedClasses: [],
|
|
|
+
|
|
|
+messageSends: ["add:"]
|
|
|
+}),
|
|
|
+$globals.Queue);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+$core.addClass('RegularExpression', $globals.Object, [], 'Kernel-Collections');
|
|
|
+
|
|
|
+$globals.RegularExpression.comment="I represent a regular expression object. My instances are JavaScript `RegExp` object.";
|
|
|
+
|
|
|
+$core.addMethod(
|
|
|
+$core.method({
|
|
|
+selector: "compile:",
|
|
|
+protocol: 'evaluating',
|
|
|
+fn: function (aString){
|
|
|
+var self=this;
|
|
|
+
|
|
|
+return $core.withContext(function($ctx1) {
|
|
|
+
|
|
|
+return self.compile(aString);
|
|
|
+return self;
|
|
|
+
|
|
|
+}, function($ctx1) {$ctx1.fill(self,"compile:",{aString:aString},$globals.RegularExpression)});
|
|
|
+
|
|
|
+},
|
|
|
+
|
|
|
+args: ["aString"],
|
|
|
+source: "compile: aString\x0a\x09<return self.compile(aString)>",
|
|
|
+referencedClasses: [],
|
|
|
+
|
|
|
+messageSends: []
|
|
|
+}),
|
|
|
+$globals.RegularExpression);
|
|
|
+
|
|
|
+$core.addMethod(
|
|
|
+$core.method({
|
|
|
+selector: "exec:",
|
|
|
+protocol: 'evaluating',
|
|
|
+fn: function (aString){
|
|
|
+var self=this;
|
|
|
+
|
|
|
+return $core.withContext(function($ctx1) {
|
|
|
+
|
|
|
+return self.exec(aString) || nil;
|
|
|
+return self;
|
|
|
+
|
|
|
+}, function($ctx1) {$ctx1.fill(self,"exec:",{aString:aString},$globals.RegularExpression)});
|
|
|
+
|
|
|
+},
|
|
|
+
|
|
|
+args: ["aString"],
|
|
|
+source: "exec: aString\x0a\x09<return self.exec(aString) || nil>",
|
|
|
+referencedClasses: [],
|
|
|
+
|
|
|
+messageSends: []
|
|
|
+}),
|
|
|
+$globals.RegularExpression);
|
|
|
+
|
|
|
+$core.addMethod(
|
|
|
+$core.method({
|
|
|
+selector: "test:",
|
|
|
+protocol: 'evaluating',
|
|
|
+fn: function (aString){
|
|
|
+var self=this;
|
|
|
+
|
|
|
+return $core.withContext(function($ctx1) {
|
|
|
+
|
|
|
+return self.test(aString);
|
|
|
+return self;
|
|
|
+
|
|
|
+}, function($ctx1) {$ctx1.fill(self,"test:",{aString:aString},$globals.RegularExpression)});
|
|
|
+
|
|
|
+},
|
|
|
+
|
|
|
+args: ["aString"],
|
|
|
+source: "test: aString\x0a\x09<return self.test(aString)>",
|
|
|
+referencedClasses: [],
|
|
|
+
|
|
|
+messageSends: []
|
|
|
+}),
|
|
|
+$globals.RegularExpression);
|
|
|
+
|
|
|
+
|
|
|
+$core.addMethod(
|
|
|
+$core.method({
|
|
|
+selector: "fromString:",
|
|
|
+protocol: 'instance creation',
|
|
|
+fn: function (aString){
|
|
|
+var self=this;
|
|
|
+
|
|
|
+return $core.withContext(function($ctx1) {
|
|
|
+
|
|
|
+var $1;
|
|
|
+$1=self._fromString_flag_(aString,"");
|
|
|
+return $1;
|
|
|
+
|
|
|
+}, function($ctx1) {$ctx1.fill(self,"fromString:",{aString:aString},$globals.RegularExpression.klass)});
|
|
|
+
|
|
|
+},
|
|
|
+
|
|
|
+args: ["aString"],
|
|
|
+source: "fromString: aString\x0a\x09\x09^ self fromString: aString flag: ''",
|
|
|
+referencedClasses: [],
|
|
|
+
|
|
|
+messageSends: ["fromString:flag:"]
|
|
|
+}),
|
|
|
+$globals.RegularExpression.klass);
|
|
|
+
|
|
|
+$core.addMethod(
|
|
|
+$core.method({
|
|
|
+selector: "fromString:flag:",
|
|
|
+protocol: 'instance creation',
|
|
|
+fn: function (aString,anotherString){
|
|
|
+var self=this;
|
|
|
+
|
|
|
+return $core.withContext(function($ctx1) {
|
|
|
+
|
|
|
+return new RegExp(aString, anotherString);
|
|
|
+return self;
|
|
|
+
|
|
|
+}, function($ctx1) {$ctx1.fill(self,"fromString:flag:",{aString:aString,anotherString:anotherString},$globals.RegularExpression.klass)});
|
|
|
+
|
|
|
+},
|
|
|
+
|
|
|
+args: ["aString", "anotherString"],
|
|
|
+source: "fromString: aString flag: anotherString\x0a\x09<return new RegExp(aString, anotherString)>",
|
|
|
+referencedClasses: [],
|
|
|
+
|
|
|
+messageSends: []
|
|
|
+}),
|
|
|
+$globals.RegularExpression.klass);
|
|
|
+
|
|
|
});
|