[squeak-dev] Need your help filling a FAQ

Hannes Hirzel hannes.hirzel at gmail.com
Sun Apr 25 18:22:38 UTC 2010


On 4/25/10, Igor Stasenko <siguctua at gmail.com> wrote:
> On 25 April 2010 20:08, Hannes Hirzel <hannes.hirzel at gmail.com> wrote:
>> Hello Igor
>>
>> Three more questions....
>>
>> 1) What are example applications of NativeBoost?
>
> Case 1) dynamic FFI callout generation:
>
> loadLibrary: libName
> 	<primitive: 'primitiveNativeCall' module: 'NativeBoostPlugin'>
>
> 	^ NBFFICallout apiCall: #( long 'LoadLibraryA' ( String )) module:
> #Kernel32
>
> Case 2) dynamic primitive generation
>
> readSignedInt32From: integerAddress
>
> 	<primitive: 'primitiveNativeCall' module: 'NativeBoostPlugin'>
> 	"
> 	Emulate the C function of form:
> 		long readSignedInt32From(long* ptr) {
> 			return *ptr;
> 		}
> 	
> 	we don't need to call anything but just read the int32 value from given
> address
> 	and let a callout generator care about value coercion
> 	"
> 	^ NBFFICallout cdecl: #(long long)
> 		emitCall: [:gen |	| asm |
> 				asm := gen asm.
> 				asm
> 					mov: (asm mem: ESP) to: EAX;
> 					mov: (asm mem: EAX) to: EAX
> 		].
>
> Case 3) an OpenGL binding i working on.. (its a bit too big to fit in there)
> ;)
>
>> 2) How much faster are they compared to regular Smalltalk code?
>
> A question is a bit vague. There is a many ways how to answer it.
> In short: Smalltalk code is interpreted by VM. Native code is
> interpreted by CPU of your computer.
> In smalltalk, you code fast, but running slow.
> In assembler, you code slow, but running fast.
>
>> 3) How do I write the native code?
>>
> Sorry, don't understand, what exactly you want to know.
> There is a helper classes, which allow you to do it more or less
> without much hurdles.
> So, if you know assembler you can write it right away.
> And sure thing, i will post an examples how to use it in my docs.

This question was answered indirectly by the examples of point one.
You have implemented an assembler in Smalltalk. A code snippet looks like

    	mov: (asm mem: ESP) to: EAX;
 	mov: (asm mem: EAX) to: EAX

--Hannes



More information about the Squeak-dev mailing list