A new version of EToys was added to project The Inbox:
http://source.squeak.org/inbox/EToys-ct.366.mcz ==================== Summary ==================== Name: EToys-ct.366 Author: ct Time: 15 October 2019, 2:41:49.434129 pm UUID: f77dfa54-471c-9049-bfc8-f03473a25099 Ancestors: EToys-mt.361 Adds basic support for reconverting ParseNodes into EToys tiles Try out: p := World assuredPlayer. e := (Player >> #liftAllPens) decompile asScriptEditorFor: p. e openInHand. =============== Diff against EToys-mt.361 =============== Item was added: + ----- Method: BlockNode>>asTileSetForPlayer: (in category '*Etoys-tiles') ----- + asTileSetForPlayer: aPlayer + + ^ self statements gather: [:statement | + [statement asStatementTileSetForPlayer: aPlayer] + ifError: [{statement asMorphicSyntaxIn: SyntaxMorph new}]]! Item was added: + ----- Method: BlockNode>>withoutImplicitReturns (in category '*Etoys-tiles') ----- + withoutImplicitReturns + + (self statements ifEmpty: [^ self]) last isReturnSelf + ifFalse: [^ self]. + ^ self copy statements: self statements allButLast! Item was added: + ----- Method: CascadeNode>>asStatementTileSetForPlayer: (in category '*Etoys-tiles') ----- + asStatementTileSetForPlayer: aPlayer + + ^ self asTileSetForPlayer: aPlayer! Item was added: + ----- Method: CascadeNode>>asTileSetForPlayer: (in category '*Etoys-tiles') ----- + asTileSetForPlayer: aPlayer + + ^ self messages gather: [:message | + message copy + receiver: self receiver; + asTileSetForPlayer: aPlayer]! Item was added: + ----- Method: CommentNode>>asTileSetForPlayer: (in category '*Etoys-tiles') ----- + asTileSetForPlayer: aPlayer + + ^ #()! Item was changed: ----- Method: EtoysDebugger>>evaluateNextTile (in category 'evaluating') ----- evaluateNextTile (scriptEditor isTextuallyCoded) ifTrue:[^ self inform: 'You can''t step through textually coded scripts.\Use a script''s tile-based representation instead.' withCRs translated]. [next = (scriptEditor tiles at: 1 ifAbsent: [nil]) ifTrue: ["We are about to evaluate the first tile" self updateStartingPosition]. + (self trailMorph ifNotNil: #batchPenTrails ifNil: [false]) - self trailMorph batchPenTrails ifTrue: [self evaluateNextTileWithBatchPenTrails] ifFalse: [next evaluateOn: self]] on: Error do: [:err || newNext | newNext := scriptEditor tiles at: 1 ifAbsent: [^ self]. newNext = next ifTrue: [err pass] ifFalse: [next := newNext]. self evaluateNextTile] ! Item was added: + ----- Method: LiteralNode>>asTileForPlayer: (in category '*Etoys-tiles') ----- + asTileForPlayer: aPlayer + + ^ aPlayer presenter constantTile: self literalValue! Item was added: + ----- Method: MessageNode>>asStatementTileSetForPlayer: (in category '*Etoys-tiles') ----- + asStatementTileSetForPlayer: aPlayer + + ^ self asTileSetForPlayer: aPlayer! Item was added: + ----- Method: MessageNode>>asTileForPlayer: (in category '*Etoys-tiles') ----- + asTileForPlayer: aPlayer + + | receiverType argumentType resultType phrase receiverTiles | + "Catch edge case: Color tile" + (self receiver isVariableNode and: [self receiver key = (Smalltalk bindingOf: #Color)]) + ifTrue: [ | source result | + source := String streamContents: (MessageSend receiver: self selector: #shortPrintOn:). + result := [Compiler evaluate: source] ifError: [nil]. + result isColor ifTrue: [^ result newTileMorphRepresentative]]. + + "Catch edge case: Test tile" + self ifConditionNormalizeAndDo: [:conditionNode :trueNode :falseNode | | compound | + compound := StandardScriptingSystem new yesNoComplexOfTiles. + compound testPart insertTileRow: (conditionNode asTileSetForPlayer: aPlayer) after: 0. + compound yesPart insertTileRow: (trueNode asTileSetForPlayer: aPlayer) after: 0. + compound noPart insertTileRow: (falseNode asTileSetForPlayer: aPlayer) after: 0. + compound enforceTileColorPolicy; layoutChanged; fullBounds. + ^ compound]. + + "Otherwise, try to build a phrase tile" + self arguments size < 2 ifFalse: [^ self convertToTileError]. + + receiverType := #unknown. + argumentType := self arguments ifEmpty: [nil] ifNotEmpty: [#unknown]. + resultType := #unkown. + phrase := PhraseTileMorph new. + phrase + setOperator: self selector key + type: resultType + rcvrType: receiverType + argType: argumentType. + receiverTiles := self receiver asTileSetForPlayer: aPlayer. + receiverTiles size = 1 ifFalse: [^ self convertToTileError]. + phrase firstSubmorph + addMorph: receiverTiles first; + hResizing: #shrinkWrap; vResizing: #shrinkWrap. + self arguments ifNotEmpty: [ | argumentTiles | + argumentTiles := self arguments first asTileSetForPlayer: aPlayer. + argumentTiles size = 1 ifFalse: [^ self convertToTileError]. + phrase lastSubmorph + setType: argumentType; + addMorph: argumentTiles first; + hResizing: #shrinkWrap; vResizing: #shrinkWrap]. + ^ phrase + hResizing: #shrinkWrap; vResizing: #shrinkWrap; + yourself! Item was added: + ----- Method: MessageNode>>ifConditionNormalizeAndDo: (in category '*Etoys-tiles') ----- + ifConditionNormalizeAndDo: aBlock + + | blocks | + blocks := self selector key + caseOf: { + [#ifTrue:ifFalse:] -> [arguments]. + [#ifFalse:ifTrue:] -> [self arguments reversed]. + [#ifTrue:] -> [self arguments copyWith: BlockNode new]. + [#ifFalse:] -> [self arguments copyWithFirst: BlockNode new] } + otherwise: [^ self]. + ^ aBlock value: self receiver value: blocks first value: blocks last! Item was added: + ----- Method: MethodNode>>asScriptEditorFor: (in category '*Etoys-tiles') ----- + asScriptEditorFor: aPlayer + + | editor | + editor := ScriptEditorMorph new. + editor + playerScripted: aPlayer; + setMorph: aPlayer costume scriptName: self selector. + (self asTileSetForPlayer: aPlayer) + withIndexDo: [:tile :index | + editor insertTileRow: {tile} after: index]. + editor + removeSpaces; + enforceTileColorPolicy; + fullBounds; + scriptEdited; + allMorphsDo: #layoutChanged. + ^ editor! Item was added: + ----- Method: MethodNode>>asTileSetForPlayer: (in category '*Etoys-tiles') ----- + asTileSetForPlayer: aPlayer + + ^ self block withoutImplicitReturns asTileSetForPlayer: aPlayer! Item was added: + ----- Method: MethodTempsNode>>asTileSetForPlayer: (in category '*Etoys-tiles') ----- + asTileSetForPlayer: aPlayer + + ^ #()! Item was added: + ----- Method: ParseNode>>asStatementTileSetForPlayer: (in category '*Etoys-tiles') ----- + asStatementTileSetForPlayer: aPlayer + + ^ self convertToTileError! Item was added: + ----- Method: ParseNode>>asTileForPlayer: (in category '*Etoys-tiles') ----- + asTileForPlayer: aPlayer + "Private. Better call #asTileMorphsForPlayer:." + + ^ self convertToTileError! Item was added: + ----- Method: ParseNode>>asTileSetForPlayer: (in category '*Etoys-tiles') ----- + asTileSetForPlayer: aPlayer + + ^ {self asTileForPlayer: aPlayer}! Item was added: + ----- Method: ParseNode>>convertToTileError (in category '*Etoys-tiles') ----- + convertToTileError + + ^ self error: 'Cannot convert this expression to a tile'! Item was added: + ----- Method: ReturnNode>>asTileSetForPlayer: (in category '*Etoys-tiles') ----- + asTileSetForPlayer: aPlayer + + "self isReturnSelf ifTrue: [^ #()]." + ^ self expr asTileSetForPlayer: aPlayer! Item was added: + ----- Method: VariableNode>>asTileForPlayer: (in category '*Etoys-tiles') ----- + asTileForPlayer: aPlayer + + | target | + self isSelfPseudoVariable + ifTrue: [^ aPlayer tileToRefer]. + target := self key isVariableBinding + ifTrue: [aPlayer environment at: self key key] + ifFalse: [self key]. + ^ TileMorph new + setToReferTo: target; + yourself! |
Free forum by Nabble | Edit this page |