Eliot Miranda uploaded a new version of CogAttic to project VM Maker: http://source.squeak.org/VMMaker/CogAttic-eem.2.mcz ==================== Summary ==================== Name: CogAttic-eem.2 Author: eem Time: 3 April 2017, 9:46:38.619161 am UUID: 385514d5-9588-46f5-bdcd-624613922bb4 Ancestors: CogAttic-eem.1 Move all the Spur bootstrap method prototypes and the CLosure bootstrap script to the attic. =============== Diff against CogAttic-eem.1 =============== Item was added: + ----- Method: Behavior>>BehaviorPROTOTYPEinstSize (in category '*CogAttic-method prototypes') ----- + BehaviorPROTOTYPEinstSize + "Answer the number of named instance variables + (as opposed to indexed variables) of the receiver. + Above Cog Spur the class format is + <5 bits inst spec><16 bits inst size>" + ^format bitAnd: 16rFFFF! Item was added: + ----- Method: Behavior>>BehaviorPROTOTYPEinstSpec (in category '*CogAttic-method prototypes') ----- + BehaviorPROTOTYPEinstSpec + "Answer the instance specification part of the format that defines what kind of object + an instance of the receiver is. The formats are + 0 = 0 sized objects (UndefinedObject True False et al) + 1 = non-indexable objects with inst vars (Point et al) + 2 = indexable objects with no inst vars (Array et al) + 3 = indexable objects with inst vars (MethodContext AdditionalMethodState et al) + 4 = weak indexable objects with inst vars (WeakArray et al) + 5 = weak non-indexable objects with inst vars (ephemerons) (Ephemeron) + 6 = unused + 7 = immediates (SmallInteger, Character) + 8 = unused + 9 = 64-bit indexable + 10-11 = 32-bit indexable (Bitmap) + 12-15 = 16-bit indexable + 16-23 = 8-bit indexable + 24-31 = compiled methods (CompiledMethod)" + ^(format bitShift: -16) bitAnd: 16r1F! Item was added: + ----- Method: BlockClosure>>BlockClosurePHAROPROTOTYPEsimulateValueWithArguments:caller: (in category '*CogAttic-method prototypes') ----- + BlockClosurePHAROPROTOTYPEsimulateValueWithArguments: anArray caller: aContext + "Simulate the valueWithArguments: primitive. Fail if anArray is not an array of the right arity." + | newContext sz | + newContext := (Context newForMethod: outerContext method) + setSender: aContext + receiver: outerContext receiver + method: outerContext method + closure: self + startpc: startpc. + ((newContext objectClass: anArray) ~~ Array + or: [numArgs ~= anArray size]) ifTrue: + [^Context primitiveFailTokenFor: nil]. + sz := self basicSize. + newContext stackp: sz + numArgs. + 1 to: numArgs do: + [:i| newContext at: i put: (anArray at: i)]. + 1 to: sz do: + [:i| newContext at: i + numArgs put: (self at: i)]. + ^newContext! Item was added: + ----- Method: BlockClosure>>BlockClosurePROTOTYPEsimulateValueWithArguments:caller: (in category '*CogAttic-method prototypes') ----- + BlockClosurePROTOTYPEsimulateValueWithArguments: anArray caller: aContext + "Simulate the valueWithArguments: primitive. Fail if anArray is not an array of the right arity." + | newContext sz | + newContext := (MethodContext newForMethod: outerContext method) + setSender: aContext + receiver: outerContext receiver + method: outerContext method + closure: self + startpc: startpc. + ((newContext objectClass: anArray) ~~ Array + or: [numArgs ~= anArray size]) ifTrue: + [^MethodContext primitiveFailTokenFor: nil]. + sz := self basicSize. + newContext stackp: sz + numArgs. + 1 to: numArgs do: + [:i| newContext at: i put: (anArray at: i)]. + 1 to: sz do: + [:i| newContext at: i + numArgs put: (self at: i)]. + ^newContext! Item was added: + ----- Method: ClassDescription>>ClassDescriptionPROTOTYPEupdateMethodBindingsTo: (in category '*CogAttic-method prototypes squeak') ----- + ClassDescriptionPROTOTYPEupdateMethodBindingsTo: aBinding + "ClassBuilder support for maintaining valid method bindings." + methodDict do: [:method| method methodClassAssociation: aBinding]! Item was added: + ----- Method: CogScriptsAttic class>>bootstrapClosures (in category 'closure scripts') ----- + bootstrapClosures + "CogScripts bootstrapClosures" + | rep | + Transcript clear. + rep := false + ifTrue: [MCCacheRepository default] + ifFalse: + [MCHttpRepository + location: 'http://dev.qwaq.com/ss/Oinq' + user: 'qwaq' + password: '']. + "This changes load order in Monticello such that additions come in before modifications." + (rep loadVersionFromFileNamed: 'Monticello-eem.302.mcz') load. + "This adds some prereqs the compiler uses that are loaded in later packages: + Fix the ClassBuilder so redefining CompiledMethod can add and remove class variables. + Add Object/Array>>isArray. + Add new interface for accessing inst vars & fields on initializing the compiler (Encoder)." + self bootstrapClosuresCompilerPreloadCode readStream fileIn. + "This temporarily stops Monticello from unloading code on load and warning about overwriting changes. + Since changes span multiple packages need all additions in before any deletions occur. + Can't warn about anything until the new debugger api is installed." + ChangeSet + newChangesFromStream: self bootstrapClosuresNeuterMonticelloCode readStream + named: 'neuterMonticello'. + Smalltalk at: #DoNotUnload put: true. + 1 to: 2 do: + [:i| + #( 'Compiler-eem.30.mcz' + 'Files-eem.21.mcz' + 'Exceptions-eem.14.mcz' + 'Collections-eem.55.mcz' + 'Tools-eem.45.mcz' + 'Kernel-eem.82.mcz' + 'System-eem.53.mcz' + 'Brad-eem.51.mcz' + 'Morphic-eem.38.mcz' + 'Tweak-Compiler-eem.36.mcz' + 'Tweak-Hacks-eem.30.mcz' + 'Tweak-Basic-eem.151.mcz' + 'Tweak-Core-Proto-eem.56.mcz') do: + [:pn| + Transcript clear; nextPutAll: pn; space; nextPut: $(; print: i; nextPut: $); endEntry. + (rep loadVersionFromFileNamed: pn) load]. + Smalltalk at: #DoNotUnload put: false]. + "Now remove the temporary hacks to Monticello" + (ChangeSet named: 'neuterMonticello') changedMessageList do: + [:mr| | changeRecords | + changeRecords := mr actualClass changeRecordsAt: mr methodSymbol. + changeRecords second fileIn]. + "Install BlockClosure in the specialObjectsArray" + Smalltalk recreateSpecialObjectsArray. + "Throw the switch to compile to closures" + self bootstrapClosuresClosureCompilerSwitchCode readStream fileIn. + "Recompile the system except the one method we can't yet deal with in GeniePlugin (1 too many literals)" + (Smalltalk forgetDoIts allClasses reject: [:c| c name == #GeniePlugin]) do: + [:c| + { c. c class } do: + [:b| + Transcript cr; print: b; endEntry. + b selectors asSortedCollection do: + [:s| + b recompile: s from: b]]]. + UsefulScripts postRecompileCleanup. + self inform: 'Save and quit and then run UsefulScripts postRecompileCleanup.\Rinse and repeat' withCRs! Item was added: + ----- Method: CompiledMethod class>>CompiledMethodclassPROTOTYPEheaderFlagForEncoder: (in category '*CogAttic-method prototypes') ----- + CompiledMethodclassPROTOTYPEheaderFlagForEncoder: anEncoder + anEncoder class == PrimaryBytecodeSetEncoderClass ifTrue: + [^0]. + anEncoder class == SecondaryBytecodeSetEncoderClass ifTrue: + [^SmallInteger minVal]. + self error: 'The encoder is not one of the two installed bytecode sets'! Item was added: + ----- Method: CompiledMethod class>>CompiledMethodclassPROTOTYPEinitialize (in category '*CogAttic-method prototypes') ----- + CompiledMethodclassPROTOTYPEinitialize "CompiledMethod initialize" + "Initialize class variables specifying the size of the temporary frame + needed to run instances of me." + + SmallFrame := 16. "Context range for temps+stack" + LargeFrame := 56. + PrimaryBytecodeSetEncoderClass ifNil: + [PrimaryBytecodeSetEncoderClass := EncoderForV3PlusClosures]. + SecondaryBytecodeSetEncoderClass ifNil: + [SecondaryBytecodeSetEncoderClass := EncoderForV3PlusClosures]! Item was added: + ----- Method: CompiledMethod class>>CompiledMethodclassPROTOTYPEinstallPrimaryBytecodeSet: (in category '*CogAttic-method prototypes') ----- + CompiledMethodclassPROTOTYPEinstallPrimaryBytecodeSet: aBytecodeEncoderSubclass + PrimaryBytecodeSetEncoderClass == aBytecodeEncoderSubclass ifTrue: + [^self]. + (aBytecodeEncoderSubclass inheritsFrom: BytecodeEncoder) ifFalse: + [self error: 'A bytecode set encoder is expected to be a subclass of BytecodeEncoder']. + (self allSubInstances + detect: [:m| m header >= 0 and: [m encoderClass ~~ aBytecodeEncoderSubclass]] + ifNone: []) ifNotNil: + [Warning signal: 'There are existing CompiledMethods with a different encoderClass.']. + PrimaryBytecodeSetEncoderClass := aBytecodeEncoderSubclass! Item was added: + ----- Method: CompiledMethod class>>CompiledMethodclassPROTOTYPEinstallSecondaryBytecodeSet: (in category '*CogAttic-method prototypes') ----- + CompiledMethodclassPROTOTYPEinstallSecondaryBytecodeSet: aBytecodeEncoderSubclass + PrimaryBytecodeSetEncoderClass == aBytecodeEncoderSubclass ifTrue: + [^self]. + (aBytecodeEncoderSubclass inheritsFrom: BytecodeEncoder) ifFalse: + [self error: 'A bytecode set encoder is expected to be a subclass of BytecodeEncoder']. + (self allSubInstances + detect: [:m| m header < 0 and: [m encoderClass ~~ aBytecodeEncoderSubclass]] + ifNone: []) ifNotNil: + [Warning signal: 'There are existing CompiledMethods with a different encoderClass.']. + SecondaryBytecodeSetEncoderClass := aBytecodeEncoderSubclass! Item was added: + ----- Method: CompiledMethod class>>CompiledMethodclassPROTOTYPEnewBytes:trailerBytes:nArgs:nTemps:nStack:nLits:primitive: (in category '*CogAttic-method prototypes') ----- + CompiledMethodclassPROTOTYPEnewBytes: numberOfBytes trailerBytes: trailer nArgs: nArgs nTemps: nTemps nStack: stackSize nLits: nLits primitive: primitiveIndex + "Answer an instance of me. The header is specified by the message + arguments. The remaining parts are not as yet determined." + | method pc | + nArgs > 15 ifTrue: + [^self error: 'Cannot compile -- too many arguments']. + nTemps > 63 ifTrue: + [^self error: 'Cannot compile -- too many temporary variables']. + nLits > 32768 ifTrue: + [^self error: 'Cannot compile -- too many literals']. + + method := trailer + createMethod: numberOfBytes + class: self + header: (nArgs bitShift: 24) + + (nTemps bitShift: 18) + + ((nTemps + stackSize) > SmallFrame ifTrue: [1 bitShift: 17] ifFalse: [0]) + + nLits + + (primitiveIndex > 0 ifTrue: [1 bitShift: 16] ifFalse: [0]). + primitiveIndex > 0 ifTrue: + [pc := method initialPC. + method + at: pc + 0 put: method encoderClass callPrimitiveCode; + at: pc + 1 put: (primitiveIndex bitAnd: 16rFF); + at: pc + 2 put: (primitiveIndex bitShift: -8)]. + ^method! Item was added: + ----- Method: CompiledMethod class>>CompiledMethodclassPROTOTYPEnewBytes:trailerBytes:nArgs:nTemps:nStack:nLits:primitive:flag: (in category '*CogAttic-method prototypes') ----- + CompiledMethodclassPROTOTYPEnewBytes: numberOfBytes trailerBytes: trailer nArgs: nArgs nTemps: nTemps nStack: stackSize nLits: nLits primitive: primitiveIndex flag: flag + "Answer an instance of me. The header is specified by the message + arguments. The remaining parts are not as yet determined." + | method pc | + nArgs > 15 ifTrue: + [^self error: 'Cannot compile -- too many arguments']. + nTemps > 63 ifTrue: + [^self error: 'Cannot compile -- too many temporary variables']. + nLits > 32768 ifTrue: + [^self error: 'Cannot compile -- too many literals']. + + method := trailer + createMethod: numberOfBytes + class: self + header: (nArgs bitShift: 24) + + (nTemps bitShift: 18) + + ((nTemps + stackSize) > SmallFrame ifTrue: [1 bitShift: 17] ifFalse: [0]) + + nLits + + (primitiveIndex > 0 ifTrue: [1 bitShift: 16] ifFalse: [0]) + + (flag ifTrue: [1 bitShift: 29] ifFalse: [0]). + primitiveIndex > 0 ifTrue: + [pc := method initialPC. + method + at: pc + 0 put: method encoderClass callPrimitiveCode; + at: pc + 1 put: (primitiveIndex bitAnd: 16rFF); + at: pc + 2 put: (primitiveIndex bitShift: -8)]. + ^method! Item was added: + ----- Method: CompiledMethod>>CompiledMethodPROTOTYPEencoderClass (in category '*CogAttic-method prototypes') ----- + CompiledMethodPROTOTYPEencoderClass + "Answer the encoder class that encoded the bytecodes in this method. + The sign flag bit is used by the VM to select a bytecode set. This formulation + may seem odd but this has to be fast, so no property probe unless needed." + + ^self header >= 0 + ifTrue: + [PrimaryBytecodeSetEncoderClass] + ifFalse: + [PrimaryBytecodeSetEncoderClass == SecondaryBytecodeSetEncoderClass + ifTrue: "Support for testing prior to installing another set" + [(self propertyValueAt: #encoderClass) ifNil: [SecondaryBytecodeSetEncoderClass]] + ifFalse: + [SecondaryBytecodeSetEncoderClass]]! Item was added: + ----- Method: Context>>MethodContextPROTOTYPEfailPrimitiveWith: (in category '*CogAttic-method prototypes') ----- + MethodContextPROTOTYPEfailPrimitiveWith: maybePrimFailToken + "The receiver is a freshly-created context on a primitive method. Skip the callPrimitive: + bytecode and store the primitive fail code if there is one and the method consumes it." + self skipCallPrimitive. + ((self isPrimFailToken: maybePrimFailToken) + and: [method encoderClass isStoreAt: pc in: method]) ifTrue: + [self at: stackp put: maybePrimFailToken last]! Item was added: + ----- Method: Decompiler>>DecompilerPROTOTYPEdecompile:in:method:using: (in category '*CogAttic-method prototypes squeak 4.3') ----- + DecompilerPROTOTYPEdecompile: aSelector in: aClass method: aMethod using: aConstructor + + | block node | + constructor := aConstructor. + method := aMethod. + self initSymbols: aClass. "create symbol tables" + method isQuick + ifTrue: [block := self quickMethod] + ifFalse: + [stack := OrderedCollection new: method frameSize. + lastJumpIfPcStack := OrderedCollection new. + caseExits := OrderedCollection new. + statements := OrderedCollection new: 20. + numLocalTemps := 0. + super method: method pc: method initialPC. + "skip primitive error code store if necessary" + (method primitive ~= 0 and: [self skipCallPrimitive; willStore]) ifTrue: + [pc := pc + (method encoderClass bytecodeSize: self firstByte). + tempVars := tempVars asOrderedCollection]. + block := self blockTo: method endPC + 1. + stack isEmpty ifFalse: [self error: 'stack not empty']]. + node := constructor + codeMethod: aSelector + block: block + tempVars: tempVars + primitive: method primitive + class: aClass. + method primitive > 0 ifTrue: + [node removeAndRenameLastTempIfErrorCode]. + ^node preen! Item was added: + ----- Method: EncoderForV3PlusClosures>>EncoderForV3PlusClosuresPROTOTYPEgenCallPrimitive: (in category '*CogAttic-method prototypes') ----- + EncoderForV3PlusClosuresPROTOTYPEgenCallPrimitive: primitiveIndex + "139 11101111 iiiiiiii jjjjjjjj Call Primitive #iiiiiiii + (jjjjjjjj * 256)" + (primitiveIndex < 1 or: [primitiveIndex > 65535]) ifTrue: + [self outOfRangeError: 'primitive index' index: primitiveIndex range: 1 to: 65535]. + stream + nextPut: 139; + nextPut: (primitiveIndex bitAnd: 255); + nextPut: (primitiveIndex bitShift: -8)! Item was added: + ----- Method: InstructionStream>>InstructionStreamPROTOTYPEinterpretV3ClosuresExtension:in:for: (in category '*CogAttic-method prototypes') ----- + InstructionStreamPROTOTYPEinterpretV3ClosuresExtension: offset in: method for: client + | type offset2 byte2 byte3 byte4 | + offset <= 6 ifTrue: + ["Extended op codes 128-134" + byte2 := method at: pc. pc := pc + 1. + offset <= 2 ifTrue: + ["128-130: extended pushes and pops" + type := byte2 // 64. + offset2 := byte2 \\ 64. + offset = 0 ifTrue: + [type = 0 ifTrue: [^client pushReceiverVariable: offset2]. + type = 1 ifTrue: [^client pushTemporaryVariable: offset2]. + type = 2 ifTrue: [^client pushConstant: (method literalAt: offset2 + 1)]. + type = 3 ifTrue: [^client pushLiteralVariable: (method literalAt: offset2 + 1)]]. + offset = 1 ifTrue: + [type = 0 ifTrue: [^client storeIntoReceiverVariable: offset2]. + type = 1 ifTrue: [^client storeIntoTemporaryVariable: offset2]. + type = 2 ifTrue: [self error: 'illegalStore']. + type = 3 ifTrue: [^client storeIntoLiteralVariable: (method literalAt: offset2 + 1)]]. + offset = 2 ifTrue: + [type = 0 ifTrue: [^client popIntoReceiverVariable: offset2]. + type = 1 ifTrue: [^client popIntoTemporaryVariable: offset2]. + type = 2 ifTrue: [self error: 'illegalStore']. + type = 3 ifTrue: [^client popIntoLiteralVariable: (method literalAt: offset2 + 1)]]]. + "131-134: extended sends" + offset = 3 ifTrue: "Single extended send" + [^client send: (method literalAt: byte2 \\ 32 + 1) + super: false numArgs: byte2 // 32]. + offset = 4 ifTrue: "Double extended do-anything" + [byte3 := method at: pc. pc := pc + 1. + type := byte2 // 32. + type = 0 ifTrue: [^client send: (method literalAt: byte3 + 1) + super: false numArgs: byte2 \\ 32]. + type = 1 ifTrue: [^client send: (method literalAt: byte3 + 1) + super: true numArgs: byte2 \\ 32]. + type = 2 ifTrue: [^client pushReceiverVariable: byte3]. + type = 3 ifTrue: [^client pushConstant: (method literalAt: byte3 + 1)]. + type = 4 ifTrue: [^client pushLiteralVariable: (method literalAt: byte3 + 1)]. + type = 5 ifTrue: [^client storeIntoReceiverVariable: byte3]. + type = 6 ifTrue: [^client popIntoReceiverVariable: byte3]. + type = 7 ifTrue: [^client storeIntoLiteralVariable: (method literalAt: byte3 + 1)]]. + offset = 5 ifTrue: "Single extended send to super" + [^client send: (method literalAt: byte2 \\ 32 + 1) + super: true + numArgs: byte2 // 32]. + offset = 6 ifTrue: "Second extended send" + [^client send: (method literalAt: byte2 \\ 64 + 1) + super: false + numArgs: byte2 // 64]]. + offset = 7 ifTrue: [^client doPop]. + offset = 8 ifTrue: [^client doDup]. + offset = 9 ifTrue: [^client pushActiveContext]. + byte2 := method at: pc. pc := pc + 1. + offset = 10 ifTrue: + [^byte2 < 128 + ifTrue: [client pushNewArrayOfSize: byte2] + ifFalse: [client pushConsArrayWithElements: byte2 - 128]]. + byte3 := method at: pc. pc := pc + 1. + offset = 11 ifTrue: [^client callPrimitive: byte2 + (byte3 bitShift: 8)]. + offset = 12 ifTrue: [^client pushRemoteTemp: byte2 inVectorAt: byte3]. + offset = 13 ifTrue: [^client storeIntoRemoteTemp: byte2 inVectorAt: byte3]. + offset = 14 ifTrue: [^client popIntoRemoteTemp: byte2 inVectorAt: byte3]. + "offset = 15" + byte4 := method at: pc. pc := pc + 1. + ^client + pushClosureCopyNumCopiedValues: (byte2 bitShift: -4) + numArgs: (byte2 bitAnd: 16rF) + blockSize: (byte3 * 256) + byte4! Item was added: + ----- Method: InstructionStream>>InstructionStreamPROTOTYPEnextPc: (in category '*CogAttic-method prototypes') ----- + InstructionStreamPROTOTYPEnextPc: currentByte + "Answer the pc of the next bytecode following the current one, given the current bytecode.." + + ^pc + (self method encoderClass bytecodeSize: currentByte)! Item was added: + ----- Method: InstructionStream>>InstructionStreamPROTOTYPEskipCallPrimitive (in category '*CogAttic-method prototypes') ----- + InstructionStreamPROTOTYPEskipCallPrimitive + "If the receiver's method starts with a callPrimitive: bytecode, skip it." + | method encoderClass callPrimitiveCode | + method := self method. + encoderClass := method encoderClass. + callPrimitiveCode := encoderClass callPrimitiveCode. + (method byteAt: pc) = callPrimitiveCode ifTrue: + [pc := pc + (encoderClass bytecodeSize: callPrimitiveCode)]! Item was added: + ----- Method: MCClassDefinition>>MCClassDefinitionPROTOTYPEkindOfSubclass (in category '*CogAttic-method prototypes squeak 4.3') ----- + MCClassDefinitionPROTOTYPEkindOfSubclass + type = #normal ifTrue: [^' subclass: ']. + type = #variable ifTrue: [^' variableSubclass: ']. + type = #bytes ifTrue: [^' variableByteSubclass: ']. + type = #compiledMethod ifTrue: [^' variableByteSubclass: ' ]. + type = #words ifTrue: [^' variableWordSubclass: ']. + type = #weak ifTrue: [^' weakSubclass: ' ]. + type = #ephemeron ifTrue: [^' ephemeronSubclass: ' ]. + type = #immediate ifTrue: [^' immediateSubclass: ' ]. + self error: 'Unrecognized class type'! Item was added: + ----- Method: MCMethodDefinition>>MCMethodDefinitionPROTOTYPEinitializeWithClassName:classIsMeta:selector:category:timeStamp:source: (in category '*CogAttic-method prototypes squeak 4.3') ----- + MCMethodDefinitionPROTOTYPEinitializeWithClassName: classString + classIsMeta: metaBoolean + selector: selectorString + category: catString + timeStamp: timeString + source: sourceString + className := classString asSymbol. + selector := selectorString asSymbol. + category := catString ifNil: [Categorizer default] ifNotNil: [catString asSymbol]. + timeStamp := timeString. + classIsMeta := metaBoolean. + source := sourceString withSqueakLineEndings! Item was added: + ----- Method: MethodNode>>MethodNodePROTOTYPEgenerate:using: (in category '*CogAttic-method prototypes') ----- + MethodNodePROTOTYPEgenerate: trailer using: aCompiledMethodClass + "The receiver is the root of a parse tree. Answer an instance of aCompiledMethodClass. + The argument, trailer, is arbitrary but is typically either the reference to the source code + that is stored with every CompiledMethod, or an encoding of the method's temporary names." + + | primErrNode blkSize nLits locals literals stack header method | + self generate: trailer + using: aCompiledMethodClass + ifQuick: + [:m | + encoder noteBlockExtent: (0 to: 2) hasLocals: arguments. + m literalAt: 2 put: encoder associationForClass; + properties: properties. + ^m]. + primErrNode := self primitiveErrorVariableName ifNotNil: + [encoder fixTemp: self primitiveErrorVariableName]. + self ensureClosureAnalysisDone. + encoder rootNode: self. "this is for BlockNode>>sizeCodeForClosureValue:" + blkSize := (block sizeCodeForEvaluatedValue: encoder) + + (primitive > 0 + ifTrue: [encoder sizeCallPrimitive: primitive] + ifFalse: [0]) + + (primErrNode + ifNil: [0] + ifNotNil: + [primErrNode + index: arguments size + temporaries size; + sizeCodeForStore: encoder "The VM relies on storeIntoTemp: (129)"]). + locals := arguments, temporaries, (primErrNode ifNil: [#()] ifNotNil: [{primErrNode}]). + encoder noteBlockExtent: block blockExtent hasLocals: locals. + header := encoder computeMethodHeaderForNumArgs: arguments size + numTemps: locals size + numLits: (nLits := (literals := encoder allLiterals) size) + primitive: primitive. + method := trailer + createMethod: blkSize + class: aCompiledMethodClass + header: header. + 1 to: nLits do: [:lit | method literalAt: lit put: (literals at: lit)]. + encoder streamToMethod: method. + stack := ParseStack new init. + primitive > 0 ifTrue: + [encoder genCallPrimitive: primitive. + primErrNode ifNotNil: + [primErrNode emitCodeForStore: stack encoder: encoder]]. + stack position: method numTemps. + [block emitCodeForEvaluatedValue: stack encoder: encoder] + on: Error "If an attempt is made to write too much code the method will be asked" + do: [:ex| "to grow, and the grow attempt will fail in CompiledMethod class>>#new:" + ex signalerContext sender method = (CompiledMethod class>>#new:) + ifTrue: [^self error: 'Compiler code size discrepancy'] + ifFalse: [ex pass]]. + stack position ~= (method numTemps + 1) ifTrue: + [^self error: 'Compiler stack discrepancy']. + encoder methodStreamPosition ~= (method size - trailer size) ifTrue: + [^self error: 'Compiler code size discrepancy']. + method needsFrameSize: stack size - method numTemps. + method properties: properties. + ^method! Item was added: + ----- Method: MethodNode>>MethodNodePROTOTYPEgenerate:using:ifQuick: (in category '*CogAttic-method prototypes') ----- + MethodNodePROTOTYPEgenerate: trailer using: aCompiledMethodClass ifQuick: methodBlock + | v | + (primitive = 0 and: [arguments size = 0 and: [block isQuick]]) ifFalse: + [^self]. + v := block code. + v < 0 ifTrue: + [^self]. + v = LdSelf ifTrue: + [^methodBlock value: (aCompiledMethodClass toReturnSelfTrailerBytes: trailer)]. + (v between: LdTrue and: LdMinus1 + 3) ifTrue: + [^methodBlock value: (aCompiledMethodClass toReturnConstant: v - LdSelf trailerBytes: trailer)]. + v < ((CodeBases at: LdInstType) + (CodeLimits at: LdInstType)) ifTrue: + [^methodBlock value: (aCompiledMethodClass toReturnField: v trailerBytes: trailer)]. + v // 256 = 1 ifTrue: + [^methodBlock value: (aCompiledMethodClass toReturnField: v \\ 256 trailerBytes: trailer)]! Item was added: + ----- Method: MethodNode>>MethodNodePROTOTYPEprintPropertiesOn: (in category '*CogAttic-method prototypes') ----- + MethodNodePROTOTYPEprintPropertiesOn: aStream + properties ifNil: [^self]. + properties propertyKeysAndValuesDo: + [:prop :val| + aStream crtab; nextPut: $<. + prop = #on:in: + ifTrue: + [prop keywords with: val do: + [:k :v | aStream nextPutAll: k; space; nextPutAll: v; space]] + ifFalse: + [prop = #on + ifTrue: [aStream nextPutAll: prop; nextPutAll:': '; nextPutAll: val] + ifFalse: [aStream nextPutAll: prop; nextPutAll:': '; print: val]]. + aStream nextPut: $>]! |
Free forum by Nabble | Edit this page |