Alright, Eliot! I finally got the changes made. You know that time when you have 2 images and you do the work in one and forget, then delete that one and have to recode all those changes? Exactly.
Nonetheless, I got the changes made and did a test of creating a ByteArray in a primitive/computation method:
#fecAddOrSubtractPolySelfCoefficients:selfCount:otherCoefficients:otherCount:.
In my case, I decided to create the result ByteArray in the computation method and return the resultOop to the primitive for #methodReturnValue:. Here is the primitive, followed by the computation method. This seems to work as I compiled and tested it. One consideration is that if we are in a primitive and call another, like happens in the decode methods, then I must remember to #interpreterProxy firstIndexableField: resultOop to access the array again (pass as argument to yet another compute method, for instance). Is this the best approach?
resultOop := self fecAddOrSubtractPolySelfCoefficients: selfCoefficients selfCount: selfCount otherCoefficients: otherCoefficients otherCount: otherCount.
^ interpreterProxy failed ifTrue: [interpreterProxy primitiveFail] ifFalse: [interpreterProxy methodReturnValue: resultOop].
And the computation method
resultOop := interpreterProxy instantiateClass: interpreterProxy classByteArray indexableSize: (selfCount max: otherCount). result := interpreterProxy firstIndexableField: resultOop.
^ resultOop
--- Kindly, Robert
On 6/5/21 7:39 PM, Eliot Miranda wrote:
Hi Robert,
_,,,^..^,,,_ (phone)
On Jun 4, 2021, at 11:52 AM, Robert Withers [robert.withers@pm.me](mailto:robert.withers@pm.me) wrote:
fieldSize := interpreterProxy stackIntegerValue: 1. coefficientsOop := interpreterProxy stackObjectValue: 0.
Since you check for isBytes: below you can use stackValue:. isBytes: can safely be passed any object, including immediates. So the stackObjectValue: call implies a redundant validation.
(interpreterProxy isIntegerValue: fieldSize) ifFalse: [ ^interpreterProxy primitiveFailFor: PrimErrBadArgument ].
This is implicit. stackIntegerValue: fails if the object is not a SmallInteger (retiring zero) and otherwise answers its integerValue. So you should check if stackIntegerValue: fails since its return value will always answer true to isIntegerValue:
(interpreterProxy isBytes: coefficientsOop) ifFalse: [ ^interpreterProxy primitiveFailFor: PrimErrBadArgument ].
I would write
fieldSize := interpreterProxy stackIntegerValue: 1. coefficientsOop := interpreterProxy stackValue: 0.
(interpreterProxy failed not and: [interpreterProxy isBytes: coefficientsOop]) ifFalse: [ ^interpreterProxy primitiveFailFor: PrimErrBadArgument ].
or
fieldSizeOop := interpreterProxy stackValue: 1. coefficientsOop := interpreterProxy stackValue: 0.
((interpreterProxy isIntegerObject: fieldSizeOop) and: [interpreterProxy isBytes: coefficientsOop]) ifFalse: [ ^interpreterProxy primitiveFailFor: PrimErrBadArgument ]. fieldSize := interpreterProxy integerValueOf: fieldSizeOop.