Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

serializing functions?

5 views
Skip to first unread message

Michal Wallace

unread,
Aug 13, 2003, 10:05:25 PM8/13/03
to perl6-i...@perl.org

This is just a question I've been wondering about,
that I think could be a huge PR sell for parrot
in the python world if the answer is "yes".

Could you serialize a parrot function?

In other words, if you interactively define a
function at the prompt, could you save it to
disk? (not the source code, the actual binary
representation of the function?)

Better yet, could you define a generator and
save its state to disk?

This came up last week or so on the pygame list.
It seems natural to use generators for games or
simulations with lightweight threads. But right
now, you can't actually save a generator once
you've got it, so it's kind of a pain.

Stackless python was able to do pickle generators
for a while, but I think the feature got removed.

Does this work out of the box? If not, does anyone
have any idea how to even approach this problem?

Sincerely,

Michal J Wallace
Sabren Enterprises, Inc.
-------------------------------------
contact: mic...@sabren.com
hosting: http://www.cornerhost.com/
my site: http://www.withoutane.com/
--------------------------------------

Leopold Toetsch

unread,
Aug 14, 2003, 1:35:41 AM8/14/03
to Michal Wallace, perl6-i...@perl.org
Michal Wallace <mic...@sabren.com> wrote:

> Could you serialize a parrot function?

> In other words, if you interactively define a
> function at the prompt, could you save it to
> disk? (not the source code, the actual binary
> representation of the function?)

Yes. Its almost done. It needs some more work in the packfile, changes
to innvoke (to switch packfiles on the fly) and one opcode to load the
PBC. When you want to save PMCs too, it'll be more work.

> Does this work out of the box? If not, does anyone
> have any idea how to even approach this problem?

eval.pmc:get_string() returns a packed PBC, ready to go to disc.

$ cat languages/parrot_compiler/parrot.pasm
read S0, 1000000
compreg P1, "PASM"
compile P0, P1, S0
write P0
end

(read a PASM program from STDIN to S0, compile that with the PASM
compiler and write the resulting PBC to STDOUT, thanks again to Juergen
Boemmels for providing this idea)

> Sincerely,
>
> Michal J Wallace

leo

0 new messages