diff --git a/stix/kernel/Context.st b/stix/kernel/Context.st index 847102a..aebd68f 100644 --- a/stix/kernel/Context.st +++ b/stix/kernel/Context.st @@ -22,6 +22,11 @@ ^self.ip } + #method pcplus1 + { + ^self.ip + 1 + } + #method pc: anInteger { self.ip := anInteger. @@ -107,24 +112,31 @@ self primitiveFailed. } - #method value: a { self primitiveFailed. } - #method value: a value: b { self primitiveFailed. } - #method value: a value: b value: c { self primitiveFailed. } + #method value: a value: b value: c value: d + { + + self primitiveFailed. + } + #method value: a value: b value: c value: d value: e + { + + self primitiveFailed. + } #method ifTrue: aBlock { @@ -143,88 +155,128 @@ #method whileTrue: aBlock { -## http://stackoverflow.com/questions/2500483/is-there-a-way-in-a-message-only-language-to-define-a-whiletrue-message-without + ## -------------------------------------------------- + ## Naive implementation + ## -------------------------------------------------- + ## (self value) ifFalse: [^nil]. + ## aBlock value. + ## self whileTrue: aBlock. + ## -------------------------------------------------- -## ---------------------------------------------------------------------------- + ## -------------------------------------------------- + ## If VM is built without STIX_USE_PROCSTK + ## -------------------------------------------------- + ## | pc sp | + ## sp := thisContext sp. + ## pc := thisContext pcplus1. + ## self value ifFalse: [ ^nil "^self" ]. + ## aBlock value. + ## thisContext pc: pc sp: sp. + ## -------------------------------------------------- -## ^(self value) ifTrue: [aBlock value. self whileTrue: aBlock]. - -## ---------------------------------------------------------------------------- - - ## less block context before whileTrue: is recursively sent. - ## whileTrue: is sent in a method context. - (self value) ifFalse: [^nil]. - aBlock value. - self whileTrue: aBlock. - -## ---------------------------------------------------------------------------- - -## ---------------------------------------------------------------------------- -" | pc sp xsp | - - sp := thisContext sp. - sp := sp - 1. ## decrement sp by 1 becuase thisContext pushed above affects the sp method - pc := thisContext pc. - self value ifFalse: [ ^nil "^self" ]. + ## -------------------------------------------------- + ## If VM is built with STIX_USE_PROCSTK + ## -------------------------------------------------- + | pc | + pc := thisContext pcplus1. + (self value) ifFalse: [ ^nil "^self" ]. aBlock value. - ##thisContext pc: pc - 3 sp: sp. - ##thisContext pc: pc + 2 sp: sp. - thisContext pc: pc + 1 sp: sp. - ## this +2 or - 3 above is dependent on the byte code instruction size used for 'store' - ## +2 to skip STORE_INTO_TEMP(pc) and POP_STACKTOP. - ## TODO: make it independent of the byte code size -" -## ---------------------------------------------------------------------------- - -## #