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

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

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

Michael van der Gulik-2
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.
        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/

Reply | Threaded
Open this post in threaded view
|

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

johnmci

On 30-Mar-09, at 2:41 AM, Michael van der Gulik wrote:

> Also, I've found that Slang sometimes compiles my code oddly... does
> it sometimes not give error messages when things are awry?

Yes there is an infamous bug in the prefer to allocate more memory  
versus doing yet another GC
logic that I put in a few years back were a missing '.' in slang just  
silently dropped the Slang code line

See

http://bugs.squeak.org/view.php?id=6667

--
=
=
=
========================================================================
John M. McIntosh <[hidden email]>
Corporate Smalltalk Consulting Ltd.  http://www.smalltalkconsulting.com
=
=
=
========================================================================




Reply | Threaded
Open this post in threaded view
|

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

johnmci
In reply to this post by Michael van der Gulik-2

On 30-Mar-09, at 2:41 AM, Michael van der Gulik wrote:

> 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.

Also see CArrayAccessor

--
=
=
=
========================================================================
John M. McIntosh <[hidden email]>
Corporate Smalltalk Consulting Ltd.  http://www.smalltalkconsulting.com
=
=
=
========================================================================




Reply | Threaded
Open this post in threaded view
|

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

Igor Stasenko
In reply to this post by Michael van der Gulik-2
2009/3/30 Michael van der Gulik <[hidden email]>:

> 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.