Free primitive indexes
siguctua at gmail.com
Sat Jul 14 00:10:56 UTC 2007
Thanks for fast response.
Maybe i need to explain, what i want to achieve, so you can guide me,
what is the best way for doing that.
I need only single primitive, which appear only in methods, compiled
by my special :) Compiler subclass.
The goal is to create a special compiled methods, which will invoke
any native code as primitive based on info object, which will be
encoded in method literal. This is the same way as FFI does - it
encodes FFI call in method's literal and then puts a #120 primitive in
method header. When interpreter enters the method, it calls primitive
120, which decodes info in method's literal and know what to do next,
based on this info.
I'd like to do in same fashion as FFI does, but providing own ways
what to invoke and where to get code/pointers i need to call.
The simplest way i found is to copy-paste FFI code, where it generates
compiled method and simply change primitive number, and object to put
in method literals.
For this reason i need a free indexed primitive slot.
On 14/07/07, tim Rowledge <tim at rowledge.org> wrote:
> On 13-Jul-07, at 4:42 PM, sig wrote:
> > Hello, squeak-dev,
> > I found, that numeric primitive table in squeak have many gaps, filled
> > with 'primitiveFail', and with comments like 'no longer used' and
> > other..
> > Id like to use one of the slots, but have no idea, what number is
> > really safe for use?
> > Any suggestions/reasoning?
> You don't get to use numbered primitives. That is reserved for those
> of us with god-like powers.
> Seriously, unless you are doing something quite extraordinary, don't
> even think about using numbered primitives. Write a simple named
> primitive and put it in a plugin if at all possible. If you really
> can't manage that, write a named primitive that will get left in the
> vm core.
> See, for example -
> "Pass in a non-negative value to disable the architectures
> powermanager if any, zero to enable. This is a named (not numbered)
> primitive in the null module (ie the VM)"
> | integer |
> self export: true.
> integer := self stackIntegerValue: 0.
> successFlag ifTrue: [
> self ioDisablePowerManager: integer.
> self pop: 1]. "integer; leave rcvr on stack"
> and usage-
> PowerManagement class>disablePowerManager: aInteger
> "Disable/Enable the architectures power manager by passing in nonzero
> or zero"
> <primitive: 'primitiveDisablePowerManager'> "primitiveExternalCall"
> ^ self
> There is no advantage to numbered primitives. Once the method lookup
> has been done the primitive function's address is stored in the cache
> so any primitive gets exactly the same treatment at that level. IF I
> had the time to spare I would have had a go at removing numbered
> prims altogether.
> tim Rowledge; tim at rowledge.org; http://www.rowledge.org/tim
> Do files get embarrassed when they get unzipped?
More information about the Squeak-dev