'From etoys2.1 of 8 August 2007 [latest update: #1617] on 11 September 2007 at 3:56:05 pm'! "Change Set: TempInTextual-yo Date: 11 September 2007 Author: Yoshiki Ohshima Support saving a textually coded script with temporaries into the S-expression format."! !MethodNode methodsFor: '*siss-interface' stamp: 'yo 9/11/2007 14:56'! sexpWith: aDictionary obj: obj | elems n pSexp tmp tmps | elems _ WriteStream on: (Array new: arguments size + 1). n _ SExpElement keyword: #slot. n attributeAt: #name put: 'script'. n attributeAt: #scriptName put: (selectorOrFalse isSymbol ifTrue: [selectorOrFalse] ifFalse: [selectorOrFalse key]). n attributeAt: #language put: 'Squeak'. pSexp _ aDictionary at: encoder classEncoding ifAbsent: []. n attributeAt: #playerClass put: (pSexp ifNotNil: [pSexp idref] ifNil: ['0']). 1 to: arguments size do: [:i | elems nextPut: ((SExpElement keyword: #parameter) attributeAt: #position put: i printString; attributeAt: #name put: (arguments at: i) key; yourself). ]. temporaries size > 0 ifTrue: [ tmp _ SExpElement keyword: #temporary. tmps _ WriteStream on: Array new. temporaries do: [:e | tmps nextPut: (e sexpWith: aDictionary obj: obj). ]. tmp elements: tmps contents. elems nextPut: tmp. ]. elems nextPut: (block sexpWith: aDictionary obj: obj). n addElements: elems contents. ^ n. ! ! !ParseNodeBuilder methodsFor: 'all' stamp: 'yo 9/11/2007 15:55'! literal: sexp | type value | type _ Smalltalk at: (sexp attributeAt: #type ifAbsent: []). value _ sexp attributeAt: #value ifAbsent: []. (type inheritsFrom: Symbol) ifTrue: [ value _ '#', value. ] ifFalse: [ (type inheritsFrom: String) ifTrue: [ ^ encoder encodeLiteral: value. ] ]. ^ encoder encodeLiteral: (type readFromString: value). ! ! !ParseNodeBuilder methodsFor: 'all' stamp: 'yo 9/11/2007 15:06'! script: sexp with: aDictionary in: aWorld | playerClassId playerClass selector n selOrFalse argSexp arguments block tmps | context _ aDictionary. playerClassId _ sexp attributeAt: #playerClass. playerClass _ aDictionary at: playerClassId asSymbol ifAbsent: [self error: '']. encoder _ ScriptEncoder new init: playerClass context: nil notifying: nil; referenceObject: aWorld. selector _ (sexp attributeAt: #scriptName) asSymbol. n _ MethodNode new. selOrFalse _ encoder encodeSelector: selector. tmps _ sexp elements detect: [:e | e keyword = #temporary] ifNone: [nil]. tmps ifNotNil: [ tmps elements do: [:t | self temporary: t. ]. ]. argSexp _ (sexp elements select: [:e | e keyword == #parameter]) asSortedCollection: [:a :b | (a attributeAt: #position) asNumber < (b attributeAt: #position) asNumber]. arguments _ argSexp collect: [:e | self parse: e]. block _ self parse: (sexp elements detect: [:e | e keyword == #sequence]). ^ n selector: selOrFalse arguments: arguments precedence: selector precedence temporaries: #() block: block encoder: encoder primitive: 0. ! ! !ParseNodeBuilder methodsFor: 'all' stamp: 'yo 9/11/2007 15:48'! sequence: sexp | statements ret args | args _ sexp elements select: [:e | e keyword == #parameter]. statements _ sexp elements reject: [:e | e keyword == #parameter]. args _ args collect: [:e | self blockParameter: e]. statements _ statements collect: [:e | self parse: e]. ret _ (statements size > 0 and: [statements last isMemberOf: ReturnNode]). args do: [:variable | variable scope: -1]. ^ BlockNode new arguments: args statements: statements returns: ret from: encoder. ! ! !ParseNodeBuilder methodsFor: 'all' stamp: 'yo 9/11/2007 15:05'! temporary: sexp | value | value _ sexp attributeAt: #value ifAbsent: []. ^ encoder bindTemp: value asSymbol ! !