[Vm-beginners] Return strings in numeric primitives

Mariano Martinez Peck marianopeck at gmail.com
Tue Jul 3 07:47:02 UTC 2012


On Mon, Jul 2, 2012 at 6:15 AM, David T. Lewis <lewis at mail.msen.com> wrote:

> On Sun, Jul 01, 2012 at 06:01:23PM -0300, David Leonhardt wrote:
> > mmm.... it seems like I don't understand how to try with strings...
> > ok, I need something more basic or more information.
> > Someone know where can I read about how to try strings en SLang?
> >
>
> When you create a new String object to return from your primitive,
> that object is part of the object memory managed by the VM. If you
> have the string "hello world" in some C code for your primitive,
> that string is not part of the object memory managed by the VM.
> It is just a null-terminated array of characters somewhere in the
> C program, allocated in memory somewhere outside of the Squeak
> object memory. This means that if you want your primitive to return
> a string, you should have your primitive create a new object of
> type String, copy the data from the C string into the data portion
> of the String object, and return that object as the result of the
> primitive.
>
> Thus in order for a primitive to answer the string "hello world",
> the primitive should create a new instance of a String object with
> length 11. This object will (inside the object memory) have a header
> that indicates the type of object, and enough data space to hold
> 11 bytes of char data from a C string. If you copy "hello world"
> from the C string into the data area of the new String object, then
> you will have a 'hello world' String object in the Smalltalk object
> memory. You can put that object on the stack to return it as the
> result of a primitive call, and the result will be a primitive
> that answers the string 'hello world'.
>
>
Excellent explanations.



> >
> > Are differences between how to try strings on numeric primitives and
> named
> > primitives? Because I'm doing proves with numeric primitives.
> >
>
> No, there is no difference between numeric primitives and named
> primitives. These are just two different ways of calling a primitive
> from the image. If you write a primitive to answer the string
> 'hello world', you will write it the same way regardless of whether
> it is a numbered primitive or a named primitive. But in general you
> should use named primitives whenever possible.
>
>
I wrote:
http://marianopeck.wordpress.com/2011/06/03/primitives-pragmas-literals-and-their-relation-to-compiledmethods/
http://marianopeck.wordpress.com/2011/07/06/named-primitives/

maybe it helps with something.




> Dave
>
> _______________________________________________
> VM-beginners mailing list
> VM-beginners at lists.squeakfoundation.org
> http://lists.squeakfoundation.org/mailman/listinfo/vm-beginners
>



-- 
Mariano
http://marianopeck.wordpress.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.squeakfoundation.org/pipermail/vm-beginners/attachments/20120703/ace69e05/attachment-0001.htm


More information about the VM-beginners mailing list