building a pluggable primitive

Elzbieta Chludzinska elzbieta at operamail.com
Fri Feb 2 16:58:06 UTC 2001


I'm trying to build a sample trial pluggable primitive using Slang that return 
the cosine of theta:

myCosine
|theta result|
	self export: true.
	self var: 'theta' declareC: 'float theta'.
	self var: 'result' declareC: 'float result'.
	self returnTypeC: 'float'.

	theta _ interpreterProxy stackFloatValue: 0.
	interpreterProxy success: (interpreterProxy isFloatObject: theta).

	interpreterProxy failed ifTrue:[^ nil].

	self cCode: 'printf("theta = %f\n, theta)'.
	self cCode: 'result = cos(theta)' inSmalltalk: [result_theta cos].
	self cCode: 'printf("result = %f\n", result)'.

	interpreterProxy failed ifTrue:[^ nil].
	interpreterProxy pop: 2.
	interpreterProxy push: result.

After #translate'ing the clase, I was forced to add #define HAVE_CONFIG_H to 
the generated .c file to get it compiled.

When building the *.so, I used the following commands:
	gcc -I "../Squeak-2.8/src/generated" -c Test.c
	ld -shared -o Test.so Test.o

I placed Test.so in the same directory as the VM.  I'm running Squeak2.9a.  
When I run it, I get either primitiveFailed or VM crashed.

Any suggestions???

Elzbieta





More information about the Squeak-dev mailing list