| 
									
										
										
										
											2017-01-06 09:53:40 +00:00
										 |  |  | class(#pointer) Context(Apex) | 
					
						
							| 
									
										
										
										
											2015-10-15 14:40:08 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2017-04-19 16:46:44 +00:00
										 |  |  | 	var sender, ip, sp, ntmprs. | 
					
						
							| 
									
										
										
										
											2016-03-28 13:25:36 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-06 09:53:40 +00:00
										 |  |  | 	method sender | 
					
						
							| 
									
										
										
										
											2016-03-28 13:25:36 +00:00
										 |  |  | 	{ | 
					
						
							|  |  |  | 		^self.sender | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2016-04-29 16:40:25 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-06 09:53:40 +00:00
										 |  |  | 	method isDead | 
					
						
							| 
									
										
										
										
											2016-06-23 15:35:28 +00:00
										 |  |  | 	{ | 
					
						
							|  |  |  | 		^self.ip < 0 | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2016-12-13 15:18:19 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-06 09:53:40 +00:00
										 |  |  | 	method temporaryCount | 
					
						
							| 
									
										
										
										
											2016-12-13 15:18:19 +00:00
										 |  |  | 	{ | 
					
						
							|  |  |  | 		^self.ntmprs | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-19 12:38:09 +00:00
										 |  |  | /* --------------------------------- | 
					
						
							| 
									
										
										
										
											2017-01-06 09:53:40 +00:00
										 |  |  | method varargCount | 
					
						
							| 
									
										
										
										
											2016-12-13 15:18:19 +00:00
										 |  |  | { | 
					
						
							|  |  |  | method context, | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	^do calculation... | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | for a block context, it must access homeContext first and call varargCount | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	^self.home varargCount... | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-06 09:53:40 +00:00
										 |  |  | method varargAt: index | 
					
						
							| 
									
										
										
										
											2016-12-13 15:18:19 +00:00
										 |  |  | { | 
					
						
							|  |  |  | method context | 
					
						
							|  |  |  | 	^do calculation... | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | block context... | 
					
						
							|  |  |  | 	^self.home varargAt: index | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-19 12:38:09 +00:00
										 |  |  | ---------------------------------- */ | 
					
						
							| 
									
										
										
										
											2015-10-15 14:40:08 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-29 15:03:54 +00:00
										 |  |  | class(#pointer,#final,#limited) MethodContext(Context) | 
					
						
							| 
									
										
										
										
											2015-10-15 14:40:08 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2017-04-19 16:46:44 +00:00
										 |  |  | 	var method, receiver, home, origin. | 
					
						
							| 
									
										
										
										
											2015-10-15 14:40:08 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-06 09:53:40 +00:00
										 |  |  | 	method pc | 
					
						
							| 
									
										
										
										
											2015-10-15 14:40:08 +00:00
										 |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2016-05-03 10:10:28 +00:00
										 |  |  | 		^self.ip | 
					
						
							| 
									
										
										
										
											2015-10-15 14:40:08 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-06 09:53:40 +00:00
										 |  |  | 	method pcplus1 | 
					
						
							| 
									
										
										
										
											2016-05-12 05:53:35 +00:00
										 |  |  | 	{ | 
					
						
							|  |  |  | 		^self.ip + 1 | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-06 09:53:40 +00:00
										 |  |  | 	method pc: anInteger | 
					
						
							| 
									
										
										
										
											2015-10-15 14:40:08 +00:00
										 |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2016-05-03 10:10:28 +00:00
										 |  |  | 		self.ip := anInteger. | 
					
						
							| 
									
										
										
										
											2015-10-15 14:40:08 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-27 06:29:09 +00:00
										 |  |  | 	// it is similar to the pc: method but it doesn't  | 
					
						
							|  |  |  | 	// push the return value to the stack. | 
					
						
							| 
									
										
										
										
											2017-12-03 17:08:04 +00:00
										 |  |  | 	method(#primitive) goto: pc. | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-06 09:53:40 +00:00
										 |  |  | 	method sp | 
					
						
							| 
									
										
										
										
											2015-10-15 14:40:08 +00:00
										 |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2016-05-03 10:10:28 +00:00
										 |  |  | 		^self.sp. | 
					
						
							| 
									
										
										
										
											2015-10-15 14:40:08 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-12-03 17:08:04 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-06 09:53:40 +00:00
										 |  |  | 	method sp: new_sp | 
					
						
							| 
									
										
										
										
											2015-10-15 14:40:08 +00:00
										 |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2016-06-23 15:35:28 +00:00
										 |  |  | 		self.sp := new_sp | 
					
						
							| 
									
										
										
										
											2015-10-15 14:40:08 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-06 09:53:40 +00:00
										 |  |  | 	method pc: new_pc sp: new_sp | 
					
						
							| 
									
										
										
										
											2015-10-15 14:40:08 +00:00
										 |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2016-06-23 15:35:28 +00:00
										 |  |  | 		self.ip := new_pc. | 
					
						
							|  |  |  | 		self.sp := new_sp. | 
					
						
							| 
									
										
										
										
											2015-10-15 14:40:08 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2016-03-28 13:25:36 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-06 09:53:40 +00:00
										 |  |  | 	method method | 
					
						
							| 
									
										
										
										
											2016-05-03 10:10:28 +00:00
										 |  |  | 	{ | 
					
						
							|  |  |  | 		^self.method | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2016-12-13 15:18:19 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-06 09:53:40 +00:00
										 |  |  | 	method vargCount | 
					
						
							| 
									
										
										
										
											2016-12-13 15:18:19 +00:00
										 |  |  | 	{ | 
					
						
							|  |  |  | 		^self basicSize - self class specNumInstVars - self.ntmprs | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2016-12-14 07:18:01 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-06 09:53:40 +00:00
										 |  |  | 	method vargAt: index | 
					
						
							| 
									
										
										
										
											2016-12-14 07:18:01 +00:00
										 |  |  | 	{ | 
					
						
							|  |  |  | 		^self basicAt: (index + self class specNumInstVars + self.ntmprs) | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2015-10-15 14:40:08 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-29 15:03:54 +00:00
										 |  |  | class(#pointer,#final,#limited) BlockContext(Context) | 
					
						
							| 
									
										
										
										
											2015-10-15 14:40:08 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2017-04-19 16:46:44 +00:00
										 |  |  | 	var nargs, source, home, origin. | 
					
						
							| 
									
										
										
										
											2015-10-15 14:40:08 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-06 09:53:40 +00:00
										 |  |  | 	method vargCount | 
					
						
							| 
									
										
										
										
											2016-12-14 07:18:01 +00:00
										 |  |  | 	{ | 
					
						
							|  |  |  | 		^self.home vargCount | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-06 09:53:40 +00:00
										 |  |  | 	method vargAt: index | 
					
						
							| 
									
										
										
										
											2016-12-13 15:18:19 +00:00
										 |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2016-12-14 07:18:01 +00:00
										 |  |  | 		^self.home vargAt: index | 
					
						
							| 
									
										
										
										
											2016-12-13 15:18:19 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-15 14:50:08 +00:00
										 |  |  | 	method pc | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		^self.ip | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	method pc: anInteger | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		self.ip := anInteger. | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	method sp | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		^self.sp | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	method sp: anInteger | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		self.sp := anInteger. | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	method restart | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		ip := self.source pc. | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class(#pointer) CompiledMethod(Object) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	var owner,  | 
					
						
							|  |  |  | 	    name, | 
					
						
							|  |  |  | 	    preamble, | 
					
						
							|  |  |  | 	    preamble_data_1, | 
					
						
							|  |  |  | 	    preamble_data_2, | 
					
						
							|  |  |  | 	    ntmprs, | 
					
						
							|  |  |  | 	    nargs, | 
					
						
							|  |  |  | 	    dbi_file_offset, | 
					
						
							|  |  |  | 	    dbi_method_offset. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	method preamble | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		^self.preamble | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	method preambleCode | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		/* TODO: make this a primtive for performance */ | 
					
						
							|  |  |  | 		^(self.preamble bitShift: -4) bitAnd: 16r1F. | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	method owner | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		^self.owner | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	method name | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		^self.name | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	method(#primitive) sourceText. | 
					
						
							|  |  |  | 	method(#primitive) sourceFile. | 
					
						
							|  |  |  | 	method(#primitive) sourceLine. | 
					
						
							|  |  |  | 	method(#primitive) ipSourceLine: ip. | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class CompiledBlock(Object) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	var ip, ntmprs, nargs, home. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// create a new process in the suspended state | 
					
						
							|  |  |  | 	method(#variadic,#primitive) newProcess(). | 
					
						
							|  |  |  | 	method(#variadic,#primitive) newSystemProcess(). // this method is for internal use only. never call this. | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-27 06:29:09 +00:00
										 |  |  | // TODO: how can i pass variadic arguments to newProcess | 
					
						
							|  |  |  | // method(#variadic) fork() -> how to pass them to newProcess??? | 
					
						
							| 
									
										
										
										
											2017-01-06 09:53:40 +00:00
										 |  |  | 	method fork  | 
					
						
							| 
									
										
										
										
											2015-10-15 14:40:08 +00:00
										 |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2019-06-27 06:29:09 +00:00
										 |  |  | 		// crate a new process in the runnable state | 
					
						
							| 
									
										
										
										
											2015-10-18 15:06:17 +00:00
										 |  |  | 		^self newProcess resume. | 
					
						
							| 
									
										
										
										
											2015-10-15 14:40:08 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-27 06:29:09 +00:00
										 |  |  | 	// evaluate the block | 
					
						
							| 
									
										
										
										
											2017-12-03 17:08:04 +00:00
										 |  |  | 	method(#variadic,#primitive) value(). | 
					
						
							| 
									
										
										
										
											2015-10-15 14:40:08 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-06 09:53:40 +00:00
										 |  |  | 	method value: a  | 
					
						
							| 
									
										
										
										
											2015-10-15 14:40:08 +00:00
										 |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2020-10-15 14:50:08 +00:00
										 |  |  | 		<primitive: #CompiledBlock_value> | 
					
						
							| 
									
										
										
										
											2016-01-29 04:04:39 +00:00
										 |  |  | 		self primitiveFailed. | 
					
						
							| 
									
										
										
										
											2015-10-15 14:40:08 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-01-06 09:53:40 +00:00
										 |  |  | 	method value: a value: b | 
					
						
							| 
									
										
										
										
											2015-10-15 14:40:08 +00:00
										 |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2020-10-15 14:50:08 +00:00
										 |  |  | 		<primitive: #CompiledBlock_value> | 
					
						
							| 
									
										
										
										
											2016-01-29 04:04:39 +00:00
										 |  |  | 		self primitiveFailed. | 
					
						
							| 
									
										
										
										
											2015-10-15 14:40:08 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-01-06 09:53:40 +00:00
										 |  |  | 	method value: a value: b value: c | 
					
						
							| 
									
										
										
										
											2015-10-15 14:40:08 +00:00
										 |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2020-10-15 14:50:08 +00:00
										 |  |  | 		<primitive: #CompiledBlock_value> | 
					
						
							| 
									
										
										
										
											2016-01-29 04:04:39 +00:00
										 |  |  | 		self primitiveFailed. | 
					
						
							| 
									
										
										
										
											2015-10-15 14:40:08 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-01-06 09:53:40 +00:00
										 |  |  | 	method value: a value: b value: c value: d | 
					
						
							| 
									
										
										
										
											2016-05-12 05:53:35 +00:00
										 |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2020-10-15 14:50:08 +00:00
										 |  |  | 		<primitive: #CompiledBlock_value> | 
					
						
							| 
									
										
										
										
											2016-05-12 05:53:35 +00:00
										 |  |  | 		self primitiveFailed. | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-01-06 09:53:40 +00:00
										 |  |  | 	method value: a value: b value: c value: d value: e | 
					
						
							| 
									
										
										
										
											2016-05-12 05:53:35 +00:00
										 |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2020-10-15 14:50:08 +00:00
										 |  |  | 		<primitive: #CompiledBlock_value> | 
					
						
							| 
									
										
										
										
											2016-05-12 05:53:35 +00:00
										 |  |  | 		self primitiveFailed. | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2015-10-15 14:40:08 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-06 09:53:40 +00:00
										 |  |  | 	method ifTrue: aBlock | 
					
						
							| 
									
										
										
										
											2015-10-15 14:40:08 +00:00
										 |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2019-06-27 06:29:09 +00:00
										 |  |  | 		//^(self value) ifTrue: aBlock. | 
					
						
							| 
									
										
										
										
											2017-02-02 04:46:29 +00:00
										 |  |  | 		^if (self value) { aBlock value }. | 
					
						
							| 
									
										
										
										
											2015-10-15 14:40:08 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-06 09:53:40 +00:00
										 |  |  | 	method ifFalse: aBlock | 
					
						
							| 
									
										
										
										
											2015-10-15 14:40:08 +00:00
										 |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2019-06-27 06:29:09 +00:00
										 |  |  | 		//^(self value) ifFalse: aBlock. | 
					
						
							| 
									
										
										
										
											2019-06-19 12:38:09 +00:00
										 |  |  | 		^if (self value) { /* nothing */ } else { aBlock value }. | 
					
						
							| 
									
										
										
										
											2015-10-15 14:40:08 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-06 09:53:40 +00:00
										 |  |  | 	method ifTrue: trueBlock ifFalse: falseBlock | 
					
						
							| 
									
										
										
										
											2015-10-15 14:40:08 +00:00
										 |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2019-06-27 06:29:09 +00:00
										 |  |  | 		//^(self value) ifTrue: trueBlock ifFalse: falseBlock | 
					
						
							| 
									
										
										
										
											2017-02-02 04:46:29 +00:00
										 |  |  | 		^if (self value) { trueBlock value } else { falseBlock value }. | 
					
						
							| 
									
										
										
										
											2015-10-15 14:40:08 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-06 09:53:40 +00:00
										 |  |  | 	method whileTrue: aBlock | 
					
						
							| 
									
										
										
										
											2015-10-15 14:40:08 +00:00
										 |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2019-06-19 12:38:09 +00:00
										 |  |  | 		/* -------------------------------------------------- | 
					
						
							| 
									
										
										
										
											2017-02-02 04:46:29 +00:00
										 |  |  | 		 * Naive recursive implementation | 
					
						
							|  |  |  | 		 * -------------------------------------------------- | 
					
						
							|  |  |  | 		(self value) ifFalse: [^nil]. | 
					
						
							|  |  |  | 		aBlock value.  | 
					
						
							|  |  |  | 		self whileTrue: aBlock. | 
					
						
							| 
									
										
										
										
											2019-06-19 12:38:09 +00:00
										 |  |  | 		 * -------------------------------------------------- */ | 
					
						
							| 
									
										
										
										
											2017-02-02 04:46:29 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-19 12:38:09 +00:00
										 |  |  | 		/* -------------------------------------------------- | 
					
						
							| 
									
										
										
										
											2017-02-02 04:46:29 +00:00
										 |  |  | 		 * Non-recursive implementation | 
					
						
							|  |  |  | 		 * -------------------------------------------------- | 
					
						
							| 
									
										
										
										
											2016-05-18 11:10:54 +00:00
										 |  |  | 		| pc sp | | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-12 05:53:35 +00:00
										 |  |  | 		pc := thisContext pcplus1. | 
					
						
							| 
									
										
										
										
											2016-05-18 11:10:54 +00:00
										 |  |  | 		(self value) ifFalse: [ ^nil ]. | 
					
						
							| 
									
										
										
										
											2015-10-15 14:40:08 +00:00
										 |  |  | 		aBlock value. | 
					
						
							| 
									
										
										
										
											2016-05-18 11:10:54 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-02 04:46:29 +00:00
										 |  |  | 		 * the pc: method leaves thisContext and pc in the stack after | 
					
						
							|  |  |  | 		 * having changes the instruction poointer. | 
					
						
							|  |  |  | 		 * as a result, the stack keeps growing. the goto method | 
					
						
							|  |  |  | 		 * clears thisContext and pc off the stack unlike normal methods. | 
					
						
							|  |  |  | 		 * thisContext pc: pc. | 
					
						
							| 
									
										
										
										
											2016-05-18 11:10:54 +00:00
										 |  |  | 		thisContext goto: pc. | 
					
						
							| 
									
										
										
										
											2017-02-02 04:46:29 +00:00
										 |  |  | 		 * -------------------------------------------------- *( | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-19 12:38:09 +00:00
										 |  |  | 		/* -------------------------------------------------- | 
					
						
							| 
									
										
										
										
											2017-02-02 04:46:29 +00:00
										 |  |  | 		 * Imperative implementation - == true or ~~ false? match the VM implementation | 
					
						
							| 
									
										
										
										
											2019-06-19 12:38:09 +00:00
										 |  |  | 		 * -------------------------------------------------- */ | 
					
						
							| 
									
										
										
										
											2017-02-02 04:46:29 +00:00
										 |  |  | 		while ((self value) ~~ false) { aBlock value }. | 
					
						
							| 
									
										
										
										
											2015-10-15 14:40:08 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-06 09:53:40 +00:00
										 |  |  | 	method whileTrue | 
					
						
							| 
									
										
										
										
											2016-03-28 13:25:36 +00:00
										 |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2019-06-19 12:38:09 +00:00
										 |  |  | 		/* -------------------------------------------------- | 
					
						
							| 
									
										
										
										
											2017-02-02 04:46:29 +00:00
										 |  |  | 		 * Naive recursive implementation | 
					
						
							|  |  |  | 		 * -------------------------------------------------- | 
					
						
							|  |  |  | 		(self value) ifFalse: [^nil]. | 
					
						
							|  |  |  | 		self whileTrue. | 
					
						
							|  |  |  | 		 * -------------------------------------------------- */ | 
					
						
							| 
									
										
										
										
											2016-05-12 05:53:35 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-19 12:38:09 +00:00
										 |  |  | 		/* -------------------------------------------------- | 
					
						
							| 
									
										
										
										
											2017-02-02 04:46:29 +00:00
										 |  |  | 		 * Non-recursive implementation | 
					
						
							|  |  |  | 		 * -------------------------------------------------- | 
					
						
							| 
									
										
										
										
											2016-05-12 05:53:35 +00:00
										 |  |  | 		| pc | | 
					
						
							|  |  |  | 		pc := thisContext pcplus1. | 
					
						
							| 
									
										
										
										
											2016-05-18 11:10:54 +00:00
										 |  |  | 		(self value) ifFalse: [ ^nil ]. | 
					
						
							|  |  |  | 		thisContext goto: pc. | 
					
						
							| 
									
										
										
										
											2017-02-02 04:46:29 +00:00
										 |  |  | 		 * -------------------------------------------------- */ | 
					
						
							|  |  |  | 		  | 
					
						
							| 
									
										
										
										
											2019-06-19 12:38:09 +00:00
										 |  |  | 		/* -------------------------------------------------- | 
					
						
							| 
									
										
										
										
											2017-02-02 04:46:29 +00:00
										 |  |  | 		 * Imperative implementation | 
					
						
							| 
									
										
										
										
											2019-06-19 12:38:09 +00:00
										 |  |  | 		 * -------------------------------------------------- */ | 
					
						
							| 
									
										
										
										
											2017-02-02 04:46:29 +00:00
										 |  |  | 		while ((self value) ~~ false) { }. | 
					
						
							| 
									
										
										
										
											2016-03-28 13:25:36 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-06 09:53:40 +00:00
										 |  |  | 	method whileFalse: aBlock | 
					
						
							| 
									
										
										
										
											2016-03-16 10:13:03 +00:00
										 |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2019-06-19 12:38:09 +00:00
										 |  |  | 		/* -------------------------------------------------- | 
					
						
							| 
									
										
										
										
											2017-02-02 04:46:29 +00:00
										 |  |  | 		 * Naive recursive implementation | 
					
						
							|  |  |  | 		 * -------------------------------------------------- | 
					
						
							|  |  |  | 		 (self value) ifTrue: [^nil]. | 
					
						
							|  |  |  | 		 aBlock value.  | 
					
						
							|  |  |  | 		 self whileFalse: aBlock. | 
					
						
							| 
									
										
										
										
											2019-06-19 12:38:09 +00:00
										 |  |  | 		 * -------------------------------------------------- */ | 
					
						
							| 
									
										
										
										
											2017-02-02 04:46:29 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-19 12:38:09 +00:00
										 |  |  | 		/* -------------------------------------------------- | 
					
						
							| 
									
										
										
										
											2017-02-02 04:46:29 +00:00
										 |  |  | 		 * Non-recursive implementation | 
					
						
							|  |  |  | 		 * -------------------------------------------------- | 
					
						
							|  |  |  | 		 *  The assignment to 'pc' uses the POP_INTO_TEMPVAR_1. | 
					
						
							|  |  |  | 		 *  It pops a value off the stack top, stores it to the second | 
					
						
							|  |  |  | 		 *  temporary variable(aBlock is the first temporary variable). | 
					
						
							|  |  |  | 		 *  It is a single byte instruction. 'pc' returned by  | 
					
						
							|  |  |  | 		 *  'thisContext pcplus1'' should point to the instruction after | 
					
						
							|  |  |  | 		 *  the POP_INTO_TEMPVAR_0 instruction. | 
					
						
							|  |  |  | 		 * | 
					
						
							|  |  |  | 		 *  It would need the increment of 2 if the pair of  | 
					
						
							|  |  |  | 		 *  STORE_INTO_TEMPVAR_1 and POP_STACKTOP were used.  | 
					
						
							|  |  |  | 		 *  This implementation is subject to the instructions chosen | 
					
						
							|  |  |  | 		 *  by the compiler. | 
					
						
							|  |  |  | 		 * -------------------------------------------------- | 
					
						
							| 
									
										
										
										
											2016-05-12 05:53:35 +00:00
										 |  |  | 		| pc | | 
					
						
							|  |  |  | 		pc := thisContext pcplus1. | 
					
						
							| 
									
										
										
										
											2019-06-27 06:29:09 +00:00
										 |  |  | 		(self value) ifTrue: [ ^nil ]. // ^self | 
					
						
							| 
									
										
										
										
											2016-05-12 05:53:35 +00:00
										 |  |  | 		aBlock value. | 
					
						
							| 
									
										
										
										
											2016-05-18 11:10:54 +00:00
										 |  |  | 		thisContext goto: pc. | 
					
						
							| 
									
										
										
										
											2019-06-19 12:38:09 +00:00
										 |  |  | 		 * -------------------------------------------------- */ | 
					
						
							| 
									
										
										
										
											2017-02-02 04:46:29 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-19 12:38:09 +00:00
										 |  |  | 		/* -------------------------------------------------- | 
					
						
							| 
									
										
										
										
											2017-02-02 04:46:29 +00:00
										 |  |  | 		 * Imperative implementation | 
					
						
							| 
									
										
										
										
											2019-06-19 12:38:09 +00:00
										 |  |  | 		 * -------------------------------------------------- */ | 
					
						
							| 
									
										
										
										
											2017-02-02 04:46:29 +00:00
										 |  |  | 		while ((self value) == false) { aBlock value }. | 
					
						
							| 
									
										
										
										
											2016-03-16 10:13:03 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-06 09:53:40 +00:00
										 |  |  | 	method whileFalse | 
					
						
							| 
									
										
										
										
											2016-03-28 13:25:36 +00:00
										 |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2019-06-19 12:38:09 +00:00
										 |  |  | 		/* -------------------------------------------------- | 
					
						
							| 
									
										
										
										
											2017-02-02 04:46:29 +00:00
										 |  |  | 		 * Naive recursive implementation | 
					
						
							|  |  |  | 		 * -------------------------------------------------- | 
					
						
							|  |  |  | 		(self value) ifTrue: [^nil]. | 
					
						
							|  |  |  | 		self whileFalse. | 
					
						
							| 
									
										
										
										
											2019-06-19 12:38:09 +00:00
										 |  |  | 		 * -------------------------------------------------- */ | 
					
						
							| 
									
										
										
										
											2016-05-12 05:53:35 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-19 12:38:09 +00:00
										 |  |  | 		/* -------------------------------------------------- | 
					
						
							| 
									
										
										
										
											2017-02-02 04:46:29 +00:00
										 |  |  | 		 * Non-recursive implementation | 
					
						
							|  |  |  | 		 * --------------------------------------------------  | 
					
						
							| 
									
										
										
										
											2016-05-12 05:53:35 +00:00
										 |  |  | 		| pc | | 
					
						
							|  |  |  | 		pc := thisContext pcplus1. | 
					
						
							| 
									
										
										
										
											2019-06-27 06:29:09 +00:00
										 |  |  | 		(self value) ifTrue: [ ^nil ]. // ^self | 
					
						
							| 
									
										
										
										
											2016-05-18 11:10:54 +00:00
										 |  |  | 		thisContext goto: pc. | 
					
						
							| 
									
										
										
										
											2019-06-19 12:38:09 +00:00
										 |  |  | 		* -------------------------------------------------- */ | 
					
						
							| 
									
										
										
										
											2017-02-02 04:46:29 +00:00
										 |  |  | 		while ((self value) == false) { }. | 
					
						
							| 
									
										
										
										
											2016-03-28 13:25:36 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-02-02 04:46:29 +00:00
										 |  |  | } |