[Vm-dev] Re: Having trouble with 4.2 on Linux

David T. Lewis lewis at mail.msen.com
Wed May 25 02:57:10 UTC 2011


On Tue, May 24, 2011 at 03:47:40PM -0700, Ken Causey wrote:
> 
> However I will take this opportunity to update everyone on why I finally
> got fed up with it today.  I thought to myself if the test functions
> were not being included in the plugin(and my cursory inspection suggests
> the cmake configuration does not include ffi-test.*) then perhaps the
> simplest thing I could do would be to create a simple interface to rand.
>  So I created a new subclass of ExternalLibrary and tried to add a
> testRand instance method.  However as soon as I finished typing
> '<cdecl:' I started getting debuggers popping up for every keypress
> related to parsing, I suspect having to do with Shout.  Yet I check the
> preferences and under Browsing Shout and syntaxHighlightingAsYouType
> (going from memory) are not enabled.  But in fact the syntax is being
> colored as I type.  I can't figure out how to stop it.  So I just type
> away and ignore the debuggers resulting in
> 
> testRand
>    "Test rand"
>    <cdecl: int 'rand' ()>
>    ^self externalCallFailed
> 
> and I try to accept that but it will not accept it insisting that there
> should be a return call type in the cdecl line even though I think I've
> typed one in there.  I also tried <cdecl: int 'rand' (void)> as I'm not
> sure which if either of these is correct, but the same result happens in
> both cases.

Most likely both declarations are incorrect, and that's probably what
the parser is trying to tell you.

<OT>
Of course everyone knows that writing plugins is "hard". But just in case
you run out of patience with doing it the "easy" way, consider writing a
small plugin. Commented example attached.  Compile the plugin with your VM,
then evaluate "RandPlugin next" to exercise the primitive.

  primitiveRand
    "Call the rand() clib function to obtain a positive int in the range 0 through
    16r7FFFFFFF. This will be the value of the Integer that we want to return from
    this primitive. Use #positive32BitIntegerFor: to convert this value into an object
    reference, which will be either a SmallInteger or a LargePositiveInteger. Pop
    a value from the stack (representing self), then push the integer value to be
    returned. Sender of this primitive will receive the integer object as the result
    of calling the primitive. Note, #code:inSmalltalk: provides a means of implementing
    the equivalent of rand() in Smalltalk. When running this primitive in Smalltalk
    (i.e. the interpreter simulator), the Smalltalk block will be executed rather
    than the rand() clib function."
    <export: true>
    | nextRand |
    nextRand := self
        cCode: 'rand()'
        inSmalltalk: [(Random new next * 16r7FFFFFFF) asInteger].
    self pop: 1 thenPush: (self positive32BitIntegerFor: nextRand)	

</OT>

Dave

-------------- next part --------------
'From Squeak3.11alpha of 22 May 2011 [latest update: #11440] on 24 May 2011 at 10:53:36 pm'!
InterpreterPlugin subclass: #RandPlugin
	instanceVariableNames: ''
	classVariableNames: ''
	poolDictionaries: ''
	category: 'Junk'!
!RandPlugin commentStamp: 'dtl 5/24/2011 21:46' prior: 0!
RandPlugin demonstrates how to call the C lib rand() function as a primitive.!


!RandPlugin methodsFor: 'primitives' stamp: 'dtl 5/24/2011 22:52'!
primitiveRand
	"Call the rand() clib function to obtain a positive int in the range 0 through
	16r7FFFFFFF. This will be the value of the Integer that we want to return from
	this primitive. Use #positive32BitIntegerFor: to convert this value into an object
	reference, which will be either a SmallInteger or a LargePositiveInteger. Pop
	a value from the stack (representing self), then push the integer value to be
	returned. Sender of this primitive will receive the integer object as the result
	of calling the primitive. Note, #code:inSmalltalk: provides a means of implementing
	the equivalent of rand() in Smalltalk. When running this primitive in Smalltalk
	(i.e. the interpreter simulator), the Smalltalk block will be executed rather
	than the rand() clib function."
	<export: true>
	| nextRand |
	nextRand := self
		cCode: 'rand()'
		inSmalltalk: [(Random new next * 16r7FFFFFFF) asInteger].
	self pop: 1 thenPush: (self positive32BitIntegerFor: nextRand)! !

"-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- "!

RandPlugin class
	instanceVariableNames: ''!

!RandPlugin class methodsFor: 'primitive access' stamp: 'dtl 5/24/2011 21:33'!
next
	"RandPlugin next"
	<primitive: 'primitiveRand' module: 'RandPlugin'>
	self primitiveFailed! !


More information about the Vm-dev mailing list