January 14, 2011
The interpreter implements Squeak bytecodes internally and accesses resources from the host environment through “Primitive Methods”.
“Primitive Methods” are used like any other Smalltalk methods but, instead of the method being executed within the interpreter, a call is made to the host environment.
There are two separate syntaxes for Primive Methods. The first is resolved at compile time and has the following syntax:
Here is an example primitive method in Object->System->Char:
This is a call to the .Net library function “Boolean System.Char.IsUpper(System.Char ch)”. In Smalltalk, it is called like any other method. For example,
Char isUpper: $a ==> false
Char isUpper: $A ==> true
Of course, the exact primitive method syntax will depend upon the host environment.
There are also “dynamic primitives” which are mixed directly in Smalltalk code and don’t require creating new methods.
They have a syntax that begins with “@”:
Here is an example using two dynamic primitives:
('hello world' @Substring: 3 with: 6) @ToUpper
==> ‘LO WOR’
Dynamic primitives are more convenient; compiled primitives can be more efficient and makes it easier to write code that runs in multiple environments.
In summary, the SST interpreter can access virtually any resource that is available in the host environment libraries.