[Vm-dev] Tangential: A Lisp Interpreter Implemented in Conway's Game of Life
Stéphane Rollandin
lecteur at zogotounga.net
Thu Jan 19 12:10:38 UTC 2023
The attached version (in two methods) is three times faster. I followed
Dan's suggestion in the Byte article and removed useless carry operations.
I also extended the margin for the counting forms, so that borders act
as permanent white walls (see how gliders turn into squares when hitting
a border).
Stef
-------------- next part --------------
'From Squeak6.0 of 5 July 2022 [latest update: #22104] on 19 January 2023 at 1:02:03 pm'!
!Form methodsFor: 'copying' stamp: 'spfa 1/19/2023 12:19'!
copyAllFrom: sourcePt in: sourceForm rule: rule
self copy: self boundingBox from: sourcePt in: sourceForm rule: rule ! !
-------------- next part --------------
'From Squeak6.0 of 5 July 2022 [latest update: #22104] on 19 January 2023 at 1:01:45 pm'!
!Form methodsFor: 'processing' stamp: 'spfa 1/19/2023 13:01'!
nextGeneration
"Dan Ingalls Game of Life in BitBlt from Byte81 issue, see https://archive.org/details/byte-magazine-1981-08/page/n181/mode/2up and the following pages. "
"
|life|
life := Form extent: 200 at 200.
10000 timesRepeat: [life colorAt: 200 atRandom @ 200 atRandom put: Color black].
[Sensor noButtonPressed] whileTrue: [
life nextGeneration.
(life magnifyBy: 4) displayAt: 10 at 50].
Display restore.
"
| ext carry2 carry4 nbr1 nbr2 nbr4 zp np |
ext := self extent + (4 at 4).
nbr1 := Form extent: ext. "ones bit of count"
nbr2 := Form extent: ext. "twos bit of count"
nbr4 := Form extent: ext. "fours bit of count"
carry2 := Form extent: ext. "carry ones overflow into twos"
carry4 := Form extent: ext. "carry twos overflow into fours"
zp := 0 at 0.
np := -1 @ -1.
nbr1 copyAllFrom: zp in: self rule: Form reverse.
{2 at 0 . 0 at 2} do: [:offset |
"c2 := 1s & self"
carry2 copyAllFrom: zp in: nbr1 rule: Form over.
carry2 copyAllFrom: offset in: self rule: Form and.
"1s ^= self"
nbr1 copyAllFrom: offset in: self rule: Form reverse.
"2s ^= c2"
nbr2 copyAllFrom: zp in: carry2 rule: Form reverse.
].
{1 at 0 . 0 at 1 . 2 at 1 . 1 at 2 . 2 at 2} do: [:offset |
"c2 := 1s & self"
carry2 copyAllFrom: zp in: nbr1 rule: Form over.
carry2 copyAllFrom: offset in: self rule: Form and.
"c4 := 2s & c2"
carry4 copyAllFrom: zp in: nbr2 rule: Form over.
carry4 copyAllFrom: zp in: carry2 rule: Form and.
"1s ^= self"
nbr1 copyAllFrom: offset in: self rule: Form reverse.
"2s ^= c2"
nbr2 copyAllFrom: zp in: carry2 rule: Form reverse.
"4s ^= c4"
nbr4 copyAllFrom: zp in: carry4 rule: Form reverse.
].
"1s &= 2s"
nbr1 copyAllFrom: zp in: nbr2 rule: Form and.
"self &= 2s"
self copyAllFrom: np in: nbr2 rule: Form and.
"self |= (1s & 2s)"
self copyAllFrom: np in: nbr1 rule: Form under.
"self &= !!4s"
self copyAllFrom: np in: nbr4 rule: 4.
! !
More information about the Vm-dev
mailing list