Slang - self primitive: parameters:

Brad Fuller brad at sonaural.com
Wed Dec 14 18:49:52 UTC 2005


tim Rowledge wrote:

>
> On 13-Dec-05, at 6:03 PM, Brad Fuller wrote:
>
>> Brad Fuller wrote:
>>
>>> Hello all,
>>>
>>> I'm trying to generate a 'ulong' in Slang using the "self  
>>> primitive: parameters:" method.
>>
> Don't think that is likely to work. There isn't really an unsigned  
> long type in Smalltalk - the class Unsigned is only used in some of  
> the strange TestOSAPlugin prims along with #asOop: which tries to  
> make a valid positive 32bit  number out of it. Take a look for  
> references to the class Unsigned to see what I mean.
>
> If what you want is to extract the param and treat it as an unsigned  
> long (you might also need to think about 64bitness) then you will  
> need to pass in a SmallInteger or possibly a LargePositiveInteger -  
> which means using Oop - and coerce it later.

I wanted to make sure that I chose the right "type" to work on all 
platforms today. I didn't even think about 64bit! Thanks.
 
The result in this particular param is a bit representation in 16bits 
and one of the potential returns is 0x80000000. So, if I use 
LargePositiveInteger would that be ok and not have a possible conversion 
issue (going from C to Squeak) with the high bit set? I'm still trying 
to get my head around all of this. I'm going thru Andrew's "Extending 
the Squeak Virtual Machine", which is great, but not all the easy tricks 
(like self primitive: parameters:) are in there --- so I'm combing the 
other plugins for help.

> Further to add to this thread:
>
> I need to return a char pointer from a primitive back to Squeak,  but 
> I can't find out how to do it in Slang. Can anyone give me  pointers?
> I doubt you really want to return a char pointer; what use would it be?
> If you really want to have the pointer - it is a real not-in-object- 
> space pointer isn't it? - then you'd need to return it as a number  
> and then do the right thing with it when you call some other prim  
> that can make sense of it. For example, we pass file structure  
> pointers up to Squeak from the FilePlugin and only look at them in  
> prims.
> If you actually want the String, then you need to create a String  
> object and copy the chars from your pointer into the String instance.

Yes, I do really want the text that the char * is pointing to. Duh.

> Take a look at MIDIPlugin>primitiveMIDIGetPortName: where the nameObj  
> is a createdString and the C call memcpy() is used to fill it.

>>    ^text asValue: String.
>
> bad; this is not converting text into a String, it is assuming text  
> is already a String object and giving you the C pointer that would be  
> valid if you treat it as a string. Poor choice of name, maybe. More  
> often than not you'll see the code rather more directly using  
> "interpreterProxy firstIndexableField: nameOop" instead. 

Right. I got it now. Thanks!

brad



More information about the Vm-dev mailing list