Robin Redeker <[EMAIL PROTECTED]> wrote:
> Hello!

> The last weeks i've been in joy to implement a small vm for a
> special runtime enviroment. As i'm a regular reader of the perl.perl6.*
> mailing lists and know about parrot. I wondered how easy it would be
> to throw away my own vm solution and use parrot.
> There are currently only two things that bug me a little bit:

> 1. i wonder how to load bytecode from the memory to parrot when
> embedding it. i've read embed.pod and couldn't find a function that let me
> create a packfile or something i can run, from a memory buffer that holds the
> bytecode.

from src/embed.c:Parrot_readbc()

  pf = PackFile_new(interpreter, is_mapped);
  PackFile_unpack(interpreter, pf, (opcode_t *)program_code, program_size);

albeit it isn't part of the official embedding API (yet).

> 2. as i currently use refcounting and like the timely destruction
> semantics, i wondered whether parrot can give me that.

Yes.

> I've read that parrot wants to do a gc run over special marked objects, that
> 'need' timely destruction. (correct me there..)

You can flag a PMC for timely destruction:

  needs_destroy $P0

On subroutine return (or scope exit) you can trigger a lazy DOD run,
which does nothing if there aren't any objects that need timely
destruction:

  sweep 1    # lazy DOD

This will eventually be replaced by:

  enter_scope 0 | 1  # NEEDS_TIMELY_DESTRUCTION
  exit_scope

or some such. (Currently the register frame, where the "sweep 1" is in,
keeps these objects alive, so the lazy DOD run can only be run after the
register frame is discarded)

> So, what would happen if i have many marked objects and call subroutines
> often?

We'll try to make the lazy DOD run as fast as possible. Objects that
need timely destruction are counted. If all such objects have been seen
during DOD, the DOD run is aborted.

> Or are there any other plans? What do other languages do, which
> have refcounting and want to port to parrot?

You might have a look at ponie (perl5 on parrot). And, while Python
doesn't guarantee timely destruction, people nethertheless rely on it,
because CPython provides timely destruction due to refcounting.

That means: most of our major target HLLs need timely destruction and
we'll provide it.

> cya,
> Robin

leo

Reply via email to