[squeak-dev] Coding in Slang; array access??

Igor Stasenko siguctua at gmail.com
Mon Mar 30 17:19:01 UTC 2009


2009/3/30 Michael van der Gulik <mikevdg at gmail.com>:
> Hi.
>
> I'm working on http://bugs.squeak.org/view.php?id=7320. Generally,
> it's been educational. However, I'm a bit stuck.
>
> When you're working in Slang, are there special things I need to be
> aware of when using arrays?
>
> I suspect that the array is 0-based in C, or 1-based and converted
> oddly, or something.
>
> The whole method is below, but it won't accept the index into the
> external objects array that I'm passing it; according to gdb, the
> primitive fails at the test to check that the object is of class
> Semaphore.
>
> Is there a modern image with a working version of the
> InterpreterSimulator around?
>
> Also, I've found that Slang sometimes compiles my code oddly... does
> it sometimes not give error messages when things are awry?
>
> Thanks,
> Gulik.
>
>
> primitiveInputSemaphore
>        "Register the input semaphore. The argument must be an array index
> into the external objects array, and it must point to a Semaphore
> instance. "
>        | arg dereferencedArg semaphoreClass xArray xSize xIndex |
>        arg := self stackTop.
>
>        " Check that the given argument is an Integer. "
>        (self isIntegerObject: arg) ifFalse: [ self primitiveFail. ^nil ].
>
>        xArray := self splObj: ExternalObjectsArray.
>        xSize := self stSizeOf: xArray.
>        xIndex := self integerValueOf: arg.
>
>        " Check that the argument is a valid array index. "
>        (xIndex > xSize) ifTrue: [ self primitiveFail. ^ nil. ].
>        (xIndex < 0) ifTrue: [ self primitiveFail. ^ nil ].
>
>        " Check that the given argument points to a Semaphore. "
>        dereferencedArg := self fetchPointer: xIndex ofObject: xArray.

if you passing a smalltalk array index (1-based), then to fetch same
slot from array in primitive you should pass xIndex-1
in #fetchPointer:ofObject:

>        semaphoreClass := self splObj: ClassSemaphore.
>        ((self fetchClassOf: dereferencedArg) = semaphoreClass)
>                ifFalse: [ self primitiveFail. ^ nil ].
>
>        self ioSetInputSemaphore: (self integerValueOf: arg).
>        successFlag
>                ifTrue: [self pop: 1].
>
> --
> http://gulik.pbwiki.com/
>
>



-- 
Best regards,
Igor Stasenko AKA sig.



More information about the Squeak-dev mailing list