Pocket Smalltalk Primitives

Smalltalk primitives are bindings between Smalltalk and native code functions (usually written in C or assembler). In Pocket Smalltalk primitives are attached to Smalltalk methods by number. When a method with an attached primitive is invoked, the corresponding native code function runs.

The syntax for a primitive method is:

myPrimitiveMethod
   <primitive: 100>
   self handleFailure.
Many primitives can "fail". For example, the primitive for indexed access (#basicAt:) will fail if it is given an out-of-range index. When a primitive fails, the code after the <primitive:> statement is executed. Usually this primitive failure code will just signal an error, but sometimes it is useful to attempt another course of action.

There are 512 possible primitive numbers available in Pocket Smalltalk. Numbers 0 to 255 are reserved by the virtual machine and are used to implement the standard library. Numbers 256 to 511 are available to the user.

Adding a new primitive requires writing a C (or assembly language) function and linking it into the virtual machine. You must also add a call to register_primitive to let the VM know about your new primitive.

Primitives defined by the system are listed below.

1       Object>>basicError:
2       Smalltalk class>>cleanExit
3       Smalltalk class>>runningOnDevice
4       Object>>basicSize
5       Object>>basicAt:
6       Object>>basicAt:put:
7       BlockClosure>>value
8       BlockClosure>>value:
9       BlockClosure>>value:value:
10      Behavior>>basicNew
11      Behavior>>basicNew:
12	Smalltalk class>>#collectGarbage
13	Object>>#perform:
14	Object>>#perform:with:
15	Object>>#perform:with:with:
16	Object>>#perform:with:with:with:
17	Object>>#perform:withArguments:
18	Object>>#shallowCopy
19	Object>>#identityHash
20	Object>>#become:
21	Object>>#class
22	Object>>#isKindOf:
23	Object>>#instVarAt:
24	Object>>#instVarAt:put:
25	Character>>#asInteger
26	SmallInteger>>#asCharacter
27	String>>#,
28	Smalltalk class>>#freeMemory
29	PalmOS class>>#freeMemory
30	Object>>#asOOP
31	(unused)
32	Context class>>#textOfSymbol:
33	Behavior class>>#nameOfClass:
34	Context class>>#stackSlotsForContext:
35	Context class>>#receiverForContext:
36	Context class>>#selectorForContext:
37	(unused)
38	Context class>>#stackSlotAt:forContext:
39	(unused)
40	String>>#=
41	Character>>#testCharBit:
42	CPointer>>#byteAt:
43	CPointer>>#byteAt:put:
44	CPointer>>#wordAt:
45	CPointer>>#wordAt:put:
46	CPointer>>#dwordAt:
47	CPointer>>#dwordAt:put:
48	String>>#copyToHeap
49	Object>>#basicChangeClassTo:
50	String>>#hash
51..59  (unused)
60      Array>>#expandedBy:
61	ByteArray>>#expandedBy:
62	StringWriteStream>>#nextPut:
63	StringWriteStream>>#nextPutAll:
64	Array>>#copyFrom:to:
65	ByteArray>>#copyFrom:to:
66..69	(unused)
70      Integer>>#+
71	Integer>>#-
72	Integer>>#*
73	Integer>>#bitAnd:
74	Integer>>#bitOr:
75	Integer>>#bitXor:
76	Integer>>#//
77	Integer>>#quo:
78	Integer>>#gcd:
79	Integer>>#<
80	Integer>>#<=
81	Integer>>#>
82	Integer>>#>=
83	Integer>>#=
84	Integer>>#~=
85	Integer>>#rem:
86	Integer>>#mod:
87	Integer>>#bitShift:
88	Integer>>#printString
89	(unused)
90	Double>>#printString
91	Double>>#asInteger
92	Integer>>#asDouble
93	Double>>#+
94	Double>>#-
95	Double>>#*
96	Double>>#/
97	Double>>#<
98	Double>>#=
99	(unused)
100	Double>>#unary:
101	Double>>#rem:


Andrew Brault
Last modified: Wed Jan 20 12:46:13 1999