[Pharo-project] [NativeBoost] little improvement
this method doesn't tell why it fails when coercion fails, here is a change proposed that will save many debugging hours. pushAsPointer: gen "by default, push argument as a bytearray ptr" "may accept: - nil - variable bytes oop - external address " | asm proxy notNil done oop notExternalAddress | asm := gen asm. proxy := gen proxy. done := asm uniqueLabelName: 'done'. oop := gen reserveTemp. "load argument oop" loader emitLoad: gen to: oop. "handle nils, if we care" gen optCoerceNilToNull ifTrue: [ notNil := asm uniqueLabelName: 'notNil'. proxy nilObject. asm cmp: asm EAX with: oop; jne: notNil; xor: asm EAX with: asm EAX; push: asm EAX; jmp: done; label: notNil. ]. "handle ExternalAddress, if we care" gen optAllowExternalAddressPtr ifTrue: [ | oopClass | oopClass := gen reserveTemp. notExternalAddress := asm uniqueLabelName: 'notExternalAddress'. proxy fetchClassOf: oop. asm mov: asm EAX to: oopClass. gen emitFetchClass: NBExternalAddress. asm cmp: asm EAX with: oopClass. asm jne: notExternalAddress. proxy fetchPointer: 0 ofObject: oop. asm push: asm EAX. asm jmp: done. asm label: notExternalAddress. gen releaseTemps: 1. ]. "the last case is a byte/word array, simply push a pointer to first indexable field of oop" gen optAllowByteArraysPtr ifTrue: [ proxy isBytesOrWords: oop ifNotJumpTo: gen failedLabel. proxy firstIndexableField: oop. asm push: asm EAX. asm jmp: done. ]. asm jmp: gen failedLabel. *<----- change to: gen failWithCode: NBPrimErrBadArgument .* asm label: done. gen releaseTemps: 1. -- Lic. Javier Pimás Ciudad de Buenos Aires
Yes. But there are multiple places like that, because initially i made it working on squeak vm, where primitives has no error codes. now, of course, with Cog, we can report more details , as to what is wrong and where. Javier, i preparing a new config, which will update a debugging support for NB primitives, which will work past 14402 pharo. Because without it, you cannot debug the NB calls. See http://code.google.com/p/pharo/issues/detail?id=5459 for details. On 19 March 2012 16:21, Javier Pimás <elpochodelagente@gmail.com> wrote:
this method doesn't tell why it fails when coercion fails, here is a change proposed that will save many debugging hours.
pushAsPointer: gen "by default, push argument as a bytearray ptr" "may accept: - nil - variable bytes oop - external address " | asm proxy notNil done oop  notExternalAddress | asm := gen asm. proxy := gen proxy. done := asm uniqueLabelName: 'done'. oop := gen reserveTemp. "load argument oop" loader emitLoad: gen to: oop. "handle nils, if we care" gen optCoerceNilToNull ifTrue: [ notNil := asm uniqueLabelName: 'notNil'. proxy nilObject. asm cmp: asm EAX with: oop; jne: notNil; xor: asm EAX with: asm EAX; push: asm EAX; jmp: done; label: notNil. ].
"handle ExternalAddress, if we care" gen optAllowExternalAddressPtr ifTrue: [ | oopClass | oopClass := gen reserveTemp. notExternalAddress := asm uniqueLabelName: 'notExternalAddress'. proxy fetchClassOf: oop. asm mov: asm EAX to: oopClass.
gen emitFetchClass: NBExternalAddress. asm cmp: asm EAX with: oopClass. asm jne: notExternalAddress. proxy fetchPointer: 0 ofObject: oop. asm push: asm EAX. asm jmp: done. asm label: notExternalAddress. gen releaseTemps: 1. ].
"the last case is a byte/word array, simply push a pointer to first indexable field of oop"
gen optAllowByteArraysPtr ifTrue: [ proxy isBytesOrWords: oop ifNotJumpTo: gen failedLabel. proxy firstIndexableField: oop. asm push: asm EAX. asm jmp: done. ]. asm jmp: gen failedLabel. Â <----- change to:Â gen failWithCode: NBPrimErrBadArgument . asm label: done.
gen releaseTemps: 1.
-- Lic. Javier Pimás Ciudad de Buenos Aires
-- Best regards, Igor Stasenko.
Actually, my plans were to report the actual position for argument, or even its name. This code: asm jmp: gen failedLabel. <----- change to: gen failWithCode: NBPrimErrBadArgument . will be replaces with something like: gen failWithMessage: self coercionErrorMessage And produced coercionErrorMessage can be quite descriptive, like.. if you having function void foo (int x) and you call it with wrong type (say float) it could say: "Coercion failed: a callout argument #1 should be an Integer" .. or something like that. This will require adding the 'position' ivar to NBExternalType class, so then it can produce such descriptive error messages. Or, well... since we don't know what is the purpose of this.. generator should decide by itself.. So, i would add a new protocol to generator, like: gen failCoercionFor: self ( where self is an instance of NBExternalType) then external type don't needs to know its own position (generator knows it already). -- Best regards, Igor Stasenko.
participants (2)
-
Igor Stasenko -
Javier Pimás