[Vm-dev] VM Maker: BytecodeSets.spur-cb.50.mcz
commits at source.squeak.org
commits at source.squeak.org
Sun Apr 10 17:29:47 UTC 2016
ClementBera uploaded a new version of BytecodeSets to project VM Maker:
http://source.squeak.org/VMMaker/BytecodeSets.spur-cb.50.mcz
==================== Summary ====================
Name: BytecodeSets.spur-cb.50
Author: cb
Time: 10 April 2016, 10:29:43.071998 am
UUID: df209fd7-c70c-40a9-8525-42a3d7de85ee
Ancestors: BytecodeSets.spur-cb.49
Added another convenient script for testing.
Added partial support for compilation
=============== Diff against BytecodeSets.spur-cb.49 ===============
Item was added:
+ ----- Method: EncoderForSistaV1>>sizePushFullClosure:numCopied: (in category 'special literal encodings') -----
+ sizePushFullClosure: compiledBlockLiteralIndex numCopied: numCopied
+ ^self sizeOpcodeSelector: #genPushFullClosure:numCopied: withArguments: {compiledBlockLiteralIndex.numCopied}!
Item was changed:
BlockClosure variableSubclass: #FullBlockClosure
instanceVariableNames: 'receiver'
classVariableNames: ''
poolDictionaries: ''
category: 'BytecodeSets-SistaV1'!
+ !FullBlockClosure commentStamp: 'cb 4/10/2016 10:05' prior: 0!
- !FullBlockClosure commentStamp: 'eem 4/8/2016 10:45' prior: 0!
A FullBlockClosure is a closure that can be indepdendent of any outerContext if desired. It has its own method (currently reusing the startpc inst var) and its own receiver. outerContext can be either a MethodContext/Context or nil.
Instance Variables
receiver: <Object>
Here's an example (a chunk designed to be typed into the spurreader image with this class filed in, e.g. in the simulator), circa early 2016 for creating the recursive nfib example (|nfib|nfib:=nil.nfib:=[:n|n<=1ifTrue:[1]ifFalse:[(nfib value:n-1)+(nfib value:n-2)+1]].(1to:12)collect:nfib) using FullBlockClosure:
| method closure |
method := (AssemblerMethod new
methodClass: Object;
selector: #nfib:;
numArgs: 1;
numTemps: 2;
literal: #ifTrue:ifFalse:;
pushTemporaryVariable: 0;
pushSpecialConstant: 1;
send: #<= super: false numArgs: 1;
jump: 'L1' if: false;
pushSpecialConstant: 1;
jump: 'L2';
label: 'L1';
pushRemoteTemp: 0 inVectorAt: 1;
pushTemporaryVariable: 0;
pushSpecialConstant: 1;
send: #- super: false numArgs: 1;
send: #value: super: false numArgs: 1;
pushRemoteTemp: 0 inVectorAt: 1;
pushTemporaryVariable: 0;
pushSpecialConstant: 2;
send: #- super: false numArgs: 1;
send: #value: super: false numArgs: 1;
send: #+ super: false numArgs: 1;
pushSpecialConstant: 1;
send: #+ super: false numArgs: 1;
label: 'L2';
blockReturnTop;
yourself) assemble.
closure := FullBlockClosure new: 1.
closure
outerContext: nil;
compiledBlock: method;
numArgs: 1;
receiver: nil.
closure at: 1 put: (Array with: closure).
+ (1 to: 12) collect: closure!!
+
+ Here is a second example:
+ | methodBlock outerMethod |
+ methodBlock := (AssemblerMethod new
+ methodClass: Object;
+ selector: #inblock2;
+ numArgs: 0;
+ numTemps: 1;
+ popIntoTemporaryVariable: 0;
+ blockReturnTop;
+ yourself) assemble.
+ outerMethod := (AssemblerMethod new
+ encoder: EncoderForSistaV1 new;
+ methodClass: Object;
+ selector: #foo;
+ numTemps: 0;
+ trailerData: #[0];
+ literal: #with:;
+ binding: #Array;
+ literal: 10;
+ literal: methodBlock;
+ pushSpecialConstant: 1;
+ pushFullClosure: 3 numCopied: 1;
+ send: #value super: false numArgs: 0;
+ methodReturnTop;
+ yourself) assemble.
+ self assert: (nil withArgs: #() executeMethod: outerMethod) = 1.!
- (1 to: 12) collect: closure!!!
Item was changed:
----- Method: InstructionStream>>interpretNext3ByteSistaV1Instruction:for:extA:extB:startPC: (in category '*BytecodeSets-SistaV1-decoding') -----
interpretNext3ByteSistaV1Instruction: bytecode for: client extA: extA extB: extB startPC: startPC
"Send to the argument, client, a message that specifies the next instruction.
This method handles the three-byte codes.
For a table of the bytecode set, see EncoderForSistaV1's class comment."
+ | method byte2 byte3 literal |
- | method byte2 byte3 |
method := self method.
byte2 := method at: pc.
byte3 := method at: pc + 1.
pc := pc + 2.
"we search the bytecodes by what we expect to be the static frequency."
bytecode = 248 ifTrue:
[byte3 >= 128 ifTrue:
[^client callInlinePrimitive: byte2 + (byte3 - 128 bitShift: 8)].
^client callPrimitive: byte2 + (byte3 bitShift: 8)].
bytecode = 250 ifTrue:
["** 250 11111010 eeiiikkk jjjjjjjj Push Closure Num Copied iii (+ExtA//16*8) Num Args kkk (+ ExtA\\16*8) BlockSize jjjjjjjj (+ExtB*256). ee = num extensions"
^client
pushClosureCopyNumCopiedValues: ((byte2 bitShift: -3) bitAnd: 7) + (extA // 16 bitShift: 3)
numArgs: (byte2 bitAnd: 7) + (extA \\ 16 bitShift: 3)
blockSize: byte3 + (extB bitShift: 8)].
bytecode = 251 ifTrue:
[^client pushRemoteTemp: byte2 inVectorAt: byte3].
bytecode = 252 ifTrue:
[^client storeIntoRemoteTemp: byte2 inVectorAt: byte3].
bytecode = 253 ifTrue:
[^client popIntoRemoteTemp: byte2 inVectorAt: byte3].
"249 11111001 xxxxxxxx syyyyyyy Reserved for Push Float"
"254-255 1111111 i xxxxxxxx yyyyyyyy UNASSIGNED"
+ literal := method literalAt: (extA bitShift: 8) + byte2 + 1.
+ ^client
+ pushFullClosure: literal
+ numCopied: byte3.!
- ^self unusedBytecode: client at: startPC!
More information about the Vm-dev
mailing list