<div dir="ltr">Ok.<div><br></div><div>According to my attempts, Stack and Cog Simulators are working fine (both Spur and SqueakV3). However the VM compiled to C crashes while trying to assign a block into an instance variable.</div><div><br></div><div>So something is still wrong. <br></div></div><div class="gmail_extra"><br><div class="gmail_quote">2016-01-06 14:46 GMT+01:00  <span dir="ltr">&lt;<a href="mailto:commits@source.squeak.org" target="_blank">commits@source.squeak.org</a>&gt;</span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><br>
Eliot Miranda uploaded a new version of VMMaker to project VM Maker:<br>
<a href="http://source.squeak.org/VMMaker/VMMaker.oscog-cb.1617.mcz" rel="noreferrer" target="_blank">http://source.squeak.org/VMMaker/VMMaker.oscog-cb.1617.mcz</a><br>
<br>
==================== Summary ====================<br>
<br>
Name: VMMaker.oscog-cb.1617<br>
Author: cb<br>
Time: 6 January 2016, 2:46:27.798 pm<br>
UUID: 81fe5b89-69de-45b8-9b65-f2f4a8bd187d<br>
Ancestors: VMMaker.oscog-rmacnak.1616<br>
<br>
As Eliot ntoed, I made a dumb mistake breking instance variable stores in the interpreter.<br>
<br>
This commit fixes the mistake. In addition, storing into an immutable object in a primitive now signals a no modification error instead of inappropriate error.<br>
<br>
I checked and the StackVMSimulator is working fine after this commit. Unfortunately, the CogVMSimulator does not work in my machine, likely due to other bugs. I am going to check that it works and that compilation to C works right now.<br>
<br>
=============== Diff against VMMaker.oscog-rmacnak.1616 ===============<br>
<br>
Item was changed:<br>
  ----- Method: CoInterpreterPrimitives&gt;&gt;primitiveObjectAtPut (in category &#39;object access primitives&#39;) -----<br>
  primitiveObjectAtPut<br>
        &quot;Store a literal into a CompiledMethod at the given index. Defined for CompiledMethods only.&quot;<br>
        | thisReceiver rawHeader realHeader index newValue |<br>
        newValue := self stackValue: 0.<br>
        index := self stackValue: 1.<br>
        (objectMemory isNonIntegerObject: index) ifTrue:<br>
                [^self primitiveFailFor: PrimErrBadArgument].<br>
        index := objectMemory integerValueOf: index.<br>
        thisReceiver := self stackValue: 2.<br>
        self cppIf: IMMUTABILITY<br>
+               ifTrue: [ (objectMemory isImmutable: thisReceiver) ifTrue: [ ^self primitiveFailFor: PrimErrNoModification ] ].<br>
-               ifTrue: [ (objectMemory isImmutable: thisReceiver) ifTrue: [ ^self primitiveFailFor: PrimErrInappropriate ] ].<br>
        rawHeader := self rawHeaderOf: thisReceiver.<br>
        realHeader := (self isCogMethodReference: rawHeader)<br>
                                        ifTrue: [(self cCoerceSimple: rawHeader to: #&#39;CogMethod *&#39;) methodHeader]<br>
                                        ifFalse: [rawHeader].<br>
        (index &gt; 0<br>
         and: [index &lt;= ((objectMemory literalCountOfMethodHeader: realHeader) + LiteralStart)]) ifFalse:<br>
                [^self primitiveFailFor: PrimErrBadIndex].<br>
        index = 1<br>
                ifTrue:<br>
                        [((objectMemory isNonIntegerObject: newValue)<br>
                         or: [(objectMemory literalCountOfMethodHeader: newValue) ~= (objectMemory literalCountOfMethodHeader: realHeader)]) ifTrue:<br>
                                [^self primitiveFailFor: PrimErrBadArgument].<br>
                         (self isCogMethodReference: rawHeader)<br>
                                ifTrue: [(self cCoerceSimple: rawHeader to: #&#39;CogMethod *&#39;) methodHeader: newValue]<br>
                                ifFalse: [objectMemory storePointerUnchecked: 0 ofObject: thisReceiver withValue: newValue]]<br>
                ifFalse:<br>
                        [objectMemory storePointer: index - 1 ofObject: thisReceiver withValue: newValue].<br>
        self pop: 3 thenPush: newValue!<br>
<br>
Item was changed:<br>
  ----- Method: InterpreterPrimitives&gt;&gt;primitiveFloatAtPut (in category &#39;indexing primitives&#39;) -----<br>
  primitiveFloatAtPut<br>
        &quot;Provide platform-independent access to 32-bit words comprising<br>
         a Float.  Map index 1 onto the most significant word and index 2<br>
         onto the least significant word.&quot;<br>
        | rcvr index oopToStore valueToStore |<br>
        &lt;var: #valueToStore type: #usqInt&gt;<br>
        oopToStore := self stackTop.<br>
        valueToStore := self positive32BitValueOf: oopToStore.<br>
        self successful ifFalse:<br>
                [^self primitiveFailFor: PrimErrBadArgument].<br>
        rcvr := self stackValue: 2.<br>
        index := self stackValue: 1.<br>
        (objectMemory isImmediateFloat: rcvr) ifTrue:<br>
                [^self primitiveFailFor: PrimErrBadReceiver].<br>
        self cppIf: IMMUTABILITY<br>
+               ifTrue: [ (objectMemory isImmutable: rcvr) ifTrue: [^self primitiveFailFor: PrimErrNoModification] ].<br>
-               ifTrue: [ (objectMemory isImmutable: rcvr) ifTrue: [^self primitiveFailFor: PrimErrBadReceiver] ].<br>
        index = ConstOne ifTrue:<br>
                [objectMemory storeLong32: (VMBIGENDIAN ifTrue: [0] ifFalse: [1])<br>
                        ofObject: rcvr<br>
                        withValue: valueToStore.<br>
                ^self pop: 3 thenPush: oopToStore].<br>
        index = ConstTwo ifTrue:<br>
                [objectMemory storeLong32: (VMBIGENDIAN ifTrue: [1] ifFalse: [0])<br>
                        ofObject: rcvr<br>
                        withValue: valueToStore.<br>
                ^self pop: 3 thenPush: oopToStore].<br>
        self primitiveFailFor: ((objectMemory isIntegerObject: index)<br>
                                                        ifTrue: [PrimErrBadIndex]<br>
                                                        ifFalse: [PrimErrBadArgument])!<br>
<br>
Item was changed:<br>
  ----- Method: InterpreterPrimitives&gt;&gt;primitiveIntegerAtPut (in category &#39;sound primitives&#39;) -----<br>
  primitiveIntegerAtPut<br>
        &quot;Return the 32bit signed integer contents of a words receiver&quot;<br>
        | index rcvr sz addr value valueOop |<br>
        &lt;var: &#39;value&#39; type: &#39;int&#39;&gt;<br>
        valueOop := self stackValue: 0.<br>
        index := self stackIntegerValue: 1.<br>
        value := self signed32BitValueOf: valueOop.<br>
        self successful ifFalse:<br>
                [^self primitiveFailFor: PrimErrBadArgument].<br>
        rcvr := self stackValue: 2.<br>
        (objectMemory isWords: rcvr) ifFalse:<br>
                [^self primitiveFailFor: PrimErrInappropriate].<br>
        self cppIf: IMMUTABILITY &quot;isWords: ensure non immediate&quot;<br>
+               ifTrue: [ (objectMemory isImmutable: rcvr) ifTrue: [ ^self primitiveFailFor: PrimErrNoModification ] ].<br>
-               ifTrue: [ (objectMemory isImmutable: rcvr) ifTrue: [ ^self primitiveFailFor: PrimErrInappropriate ] ].<br>
        sz := objectMemory lengthOf: rcvr.  &quot;number of fields&quot;<br>
        (index &gt;= 1 and: [index &lt;= sz]) ifFalse:<br>
                [^self primitiveFailFor: PrimErrBadIndex].<br>
        &quot;4 = 32 bits / 8&quot;<br>
        addr := rcvr + objectMemory baseHeaderSize + (index - 1 * 4). &quot;for zero indexing&quot;<br>
        value := objectMemory intAt: addr put: value.<br>
        self pop: 3 thenPush: valueOop &quot;pop all; return value&quot;<br>
  !<br>
<br>
Item was changed:<br>
  ----- Method: InterpreterPrimitives&gt;&gt;primitiveObjectAtPut (in category &#39;object access primitives&#39;) -----<br>
  primitiveObjectAtPut<br>
        &quot;Store a literal into a CompiledMethod at the given index. Defined for CompiledMethods only.&quot;<br>
        | thisReceiver index newValue |<br>
        newValue := self stackValue: 0.<br>
        index := self stackValue: 1.<br>
        ((objectMemory isNonIntegerObject: index)<br>
         or: [index = ConstOne and: [(objectMemory isNonIntegerObject: newValue)]]) ifTrue:<br>
                [^self primitiveFailFor: PrimErrBadArgument].<br>
        index := objectMemory integerValueOf: index.<br>
        thisReceiver := self stackValue: 2.<br>
        self cppIf: IMMUTABILITY<br>
+               ifTrue: [ (objectMemory isImmutable: thisReceiver) ifTrue: [ ^self primitiveFailFor: PrimErrNoModification ] ].<br>
-               ifTrue: [ (objectMemory isImmutable: thisReceiver) ifTrue: [ ^self primitiveFailFor: PrimErrInappropriate ] ].<br>
        (index &gt; 0 and: [index &lt;= ((objectMemory literalCountOf: thisReceiver) + LiteralStart)]) ifFalse:<br>
                [^self primitiveFailFor: PrimErrBadIndex].<br>
        objectMemory storePointer: index - 1 ofObject: thisReceiver withValue: newValue.<br>
        self pop: 3 thenPush: newValue!<br>
<br>
Item was changed:<br>
  ----- Method: InterpreterPrimitives&gt;&gt;primitiveShortAtPut (in category &#39;sound primitives&#39;) -----<br>
  primitiveShortAtPut<br>
        &quot;Treat the receiver, which can be indexible by either bytes or words, as an array<br>
         of signed 16-bit values. Set the contents of the given index to the given value.<br>
         Note that the index specifies the i-th 16-bit entry, not the i-th byte or word.&quot;<br>
<br>
        | index rcvr value |<br>
        value := self stackTop.<br>
        index := self stackValue: 1.<br>
        ((objectMemory isIntegerObject: value)<br>
         and: [(objectMemory isIntegerObject: index)<br>
         and: [value := objectMemory integerValueOf: value.<br>
                  (value &gt;= -32768) and: [value &lt;= 32767]]]) ifFalse:<br>
                [^self primitiveFailFor: PrimErrBadArgument].<br>
        rcvr := self stackValue: 2.<br>
        (objectMemory isWordsOrBytes: rcvr) ifFalse:<br>
                [^self primitiveFailFor: PrimErrInappropriate].<br>
        self cppIf: IMMUTABILITY &quot;isWordsOrBytes ensure non immediate&quot;<br>
+               ifTrue: [ (objectMemory isImmutable: rcvr) ifTrue: [ ^self primitiveFailFor: PrimErrNoModification ] ].<br>
-               ifTrue: [ (objectMemory isImmutable: rcvr) ifTrue: [ ^self primitiveFailFor: PrimErrInappropriate ] ].<br>
        index := objectMemory integerValueOf: index.<br>
        (index &gt;= 1 and: [index &lt;= (objectMemory num16BitUnitsOf: rcvr)]) ifFalse:<br>
                [^self primitiveFailFor: PrimErrBadIndex].<br>
        objectMemory storeShort16: index - 1 ofObject: rcvr withValue: value.<br>
        self pop: 3 thenPush: (objectMemory integerObjectOf: value)!<br>
<br>
Item was changed:<br>
  ----- Method: SpurMemoryManager&gt;&gt;isOopValidBecome: (in category &#39;become implementation&#39;) -----<br>
  isOopValidBecome: oop<br>
        &quot;Answers 0 if the oop can be become.<br>
        Answers an error code in the other case&quot;<br>
        (self isImmediate: oop) ifTrue: [^PrimErrInappropriate].<br>
        (self isPinned: oop) ifTrue: [^PrimErrObjectIsPinned].<br>
        self<br>
                cppIf: IMMUTABILITY<br>
+               ifTrue: [ (self isImmutable: oop) ifTrue: [^PrimErrNoModification] ].<br>
-               ifTrue: [ (self isImmutable: oop) ifTrue: [^PrimErrInappropriate] ].<br>
        ^ 0!<br>
<br>
Item was changed:<br>
  ----- Method: StackInterpreter&gt;&gt;extendedStoreAndPopBytecode (in category &#39;stack bytecodes&#39;) -----<br>
  extendedStoreAndPopBytecode<br>
        &lt;inline: true&gt;<br>
        self extendedStoreBytecodePop: true<br>
+       &quot;may not be reached (immutable receiver)&quot;!<br>
- !<br>
<br>
Item was changed:<br>
  ----- Method: StackInterpreter&gt;&gt;extendedStoreBytecode (in category &#39;stack bytecodes&#39;) -----<br>
  extendedStoreBytecode<br>
        &lt;inline: true&gt;<br>
+       self extendedStoreBytecodePop: false<br>
+       &quot;may not be reached (immutable receiver)&quot;!<br>
-       self extendedStoreBytecodePop: false!<br>
<br>
Item was changed:<br>
  ----- Method: StackInterpreter&gt;&gt;storeAndPopReceiverVariableBytecode (in category &#39;stack bytecodes&#39;) -----<br>
  storeAndPopReceiverVariableBytecode<br>
        &quot;Note: This code uses<br>
        storePointerUnchecked:ofObject:withValue: and does the<br>
        store check explicitely in order to help the translator<br>
        produce better code.&quot;<br>
        | rcvr top |<br>
        rcvr := self receiver.<br>
        top := self internalStackTop.<br>
        self internalPop: 1.<br>
+       self<br>
+               cCode: &quot;Slang will inline currentBytecode to a constant so this will work in C&quot;<br>
+                       [self fetchNextBytecode.<br>
+                        objectMemory<br>
+                               storePointerImmutabilityCheck: (currentBytecode bitAnd: 7)<br>
+                               ofObject: rcvr<br>
+                               withValue: top]<br>
+               inSmalltalk: &quot;But in Smalltalk we must use the currentBytecode&#39;s value, not the next.<br>
+                       We cant use the following code when generating C code as slang<br>
+                       won&#39;t inline currentBytecode correctly due to the extra temp.&quot;<br>
+                       [ | instVarIndex |<br>
+                        instVarIndex := currentBytecode bitAnd: 7.<br>
+                        self fetchNextBytecode.<br>
+                        objectMemory<br>
+                               storePointerImmutabilityCheck: instVarIndex<br>
+                               ofObject: rcvr<br>
+                               withValue: top]!<br>
-       self fetchNextBytecode.<br>
-       objectMemory storePointerImmutabilityCheck: (currentBytecode bitAnd: 7) ofObject: rcvr withValue: top.!<br>
<br>
Item was changed:<br>
  ----- Method: StackInterpreterPrimitives&gt;&gt;primitiveInstVarAtPut (in category &#39;object access primitives&#39;) -----<br>
  primitiveInstVarAtPut<br>
        | newValue index rcvr hdr fmt totalLength fixedFields |<br>
        newValue := self stackTop.<br>
        index := self stackValue: 1.<br>
        rcvr := self stackValue: 2.<br>
        ((objectMemory isNonIntegerObject: index)<br>
         or: [argumentCount &gt; 2 &quot;e.g. object:instVarAt:put:&quot;<br>
                and: [objectMemory isOopForwarded: rcvr]]) ifTrue:<br>
                [^self primitiveFailFor: PrimErrBadArgument].<br>
+       (objectMemory isImmediate: rcvr) ifTrue: [ ^ self primitiveFailFor: PrimErrInappropriate].<br>
+       self<br>
+               cppIf: IMMUTABILITY<br>
+               ifTrue: [ (objectMemory isImmutable: rcvr) ifTrue: [ ^ self primitiveFailFor: PrimErrNoModification] ].<br>
-       self cppIf: IMMUTABILITY<br>
-               ifTrue: [ (objectMemory isOopImmutable: rcvr) ifTrue: [^self primitiveFailFor: PrimErrInappropriate] ]<br>
-               ifFalse: [ (objectMemory isImmediate: rcvr) ifTrue: [^self primitiveFailFor: PrimErrInappropriate] ].<br>
        index := objectMemory integerValueOf: index.<br>
        hdr := objectMemory baseHeader: rcvr.<br>
        fmt := objectMemory formatOfHeader: hdr.<br>
        totalLength := objectMemory lengthOf: rcvr baseHeader: hdr format: fmt.<br>
        fixedFields := objectMemory fixedFieldsOf: rcvr format: fmt length: totalLength.<br>
        (index &gt;= 1 and: [index &lt;= fixedFields]) ifFalse:<br>
                [^self primitiveFailFor: PrimErrBadIndex].<br>
        (fmt = objectMemory indexablePointersFormat<br>
         and: [objectMemory isContextHeader: hdr])<br>
                ifTrue: [self externalInstVar: index - 1 ofContext: rcvr put: newValue]<br>
                ifFalse: [self subscript: rcvr with: index storing: newValue format: fmt].<br>
        self pop: argumentCount + 1 thenPush: newValue!<br>
<br>
</blockquote></div><br></div>