How to set a pointer in xtlang?

17 views
Skip to first unread message

Johannes Kroll

unread,
Sep 18, 2016, 2:54:41 PM9/18/16
to extemp...@googlegroups.com
Hi,

trying to set a pointer like this:

(xtmX (let ((ptr:i8* null))
(set! ptr (zalloc 10))))

outputs this message:

function(car): argument 1 must be:
pair argument values: (()) #<PROC car>
Trace: impc:ir:str-list-check <- impc:ir:pointer? <-
impc:ti:zone-alloc-check <- impc:ti:set-check <- impc:ti:begin-check <-
impc:ti:let-check <- for-each <- impc:ti:let-check <-
impc:ti:run-type-check* <-
impc:ti:run-type-check

How can I set the pointer?

Also, is zone memory freed automatically at some point? If so, when?

Best,
J.

Andrew Sorensen

unread,
Sep 18, 2016, 6:43:27 PM9/18/16
to extemp...@googlegroups.com
Hi Johannes,

Conceptually your code is spot on, so don't worry, you do understand what you're doing :).  In fact this really is an Extempore bug as we should be providing a reasonable/helpful error msg.

The reason your conceptually spot on code doesn't compile is that at the moment xtlang only allows you to use zalloc,halloc and salloc as direct bindings in a let.  So the following will compile successfully.

(xtmX (let ((ptr:i8* (zalloc 10))) ptr))

Yes, zone memory is automatically freed 'at some point'.  Where 'at some point' depends on context.

In the case of an expression evaluated by xtmX the zone is freed immediately after the expression is evaluated - so in the case above the memory addressed by ptr will be invalid as soon as it returns :(

While this seems a bit arbitrary (it is), in practice there are only a few rules to keep in mind for zones. Zones, are a bit tricky, so I've decided this morning that I'm going to try to make a short screencast today, rather than write a long email.  Hopefully you'll see a post about a hopefully explanatory youtube screencast later today :)

Cheers,
Andrew.




--
You received this message because you are subscribed to the Google Groups "Extempore" group.
To unsubscribe from this group and stop receiving emails from it, send an email to extemporelang+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Johannes Kroll

unread,
Sep 18, 2016, 7:20:48 PM9/18/16
to extemp...@googlegroups.com
Interesting, thanks. Looking forward to the screencast as well. :)


On Mon, 19 Sep 2016 08:43:26 +1000
Andrew Sorensen <dig...@gmail.com> wrote:

> Hi Johannes,
>
> Conceptually your code is spot on, so don't worry, you do understand what
> you're doing :). In fact this really is an Extempore bug as we should be
> providing a reasonable/helpful error msg.
>
> The reason your conceptually spot on code doesn't compile is that at the
> moment xtlang only allows you to use zalloc,halloc and salloc as direct
> bindings in a let. So the following will compile successfully.
>
> (xtmX (let ((ptr:i8* (zalloc 10))) ptr))
>
> Yes, zone memory is automatically freed 'at some point'. Where 'at some
> point' depends on context.
>
> In the case of an expression evaluated by xtmX the zone is freed
> immediately after the expression is evaluated - so in the case above the
> memory addressed by ptr will be invalid as soon as it returns :(
>
> While this seems a bit arbitrary (it is), in practice there are only a few
> rules to keep in mind for zones. Zones, are a bit tricky, so I've decided
> this morning that I'm going to try to make a short screencast today, rather
> than write a long email. Hopefully you'll see a post about a hopefully
> explanatory youtube screencast later today :)
>
> Cheers,
> Andrew.
>
>
>
> On Mon, Sep 19, 2016 at 4:54 AM, Johannes Kroll <j-k...@gmx.de> wrote:
>
> [...]
>
> --
> You received this message because you are subscribed to the Google Groups "Extempore" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to extemporelan...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages