Allison Randal > parrot > Parrot::Interpreter

Download:
parrot-1.0.0.tar.gz

Dependencies

Annotate this POD

Website

View/Report Bugs

Module Version: 20081006   Source  

NAME ^

Parrot::Interpreter - access a Parrot interpreter from Perl 5

VERSION ^

Version 20081006

SYNOPSIS ^

        # the first interpreter created in the program
        my $interp       = Parrot::Interpreter->new();

        # all subsequent interpreters need a parent
        my $child_interp = $interp->new( $interp );

        # load a file that Parrot can recognize as code
        $interp->load_file( 'some_parrot_file.pbc' );
        $interp->load_file( 'some_parrot_file.pir' );
        $interp->load_file( 'some_parrot_file.pasm' );

        # compile a string of Parrot code
        $interp->compile( $some_parrot_code );

        # find a subroutine to invoke
        my $sub_pmc       = $interp->find_global( 'some_parrot_sub' );
        my $other_sub_pmc = $interp->find_global( 'another_sub', 'NameSpace' );

        # invoke the subroutine
        my $result_pmc    = $sub_pmc->invoke( $signature, @args );

        # get the values out of it
        print "Invoking the Sub gave ", $result_pmc->get_string( $interp ), "!\n";

All Parrot access goes through an interpreter, mediated through a Parrot::Interpreter object. There is always at least one active interpreter in a system. An interpreter allows you to load code, to compile code, and to find and store global symbols in Parrot. These are usually subroutines but they may be other types of PMCs.

Memory and Resource Implications

If you have multiple active interpreters, the second and subsequent interpreters must each have an active interpreter as a parent. In general, this may not be an issue, but if you forget, you will receive strange error messages.

Note that the parent interpreter must outlive its children, in Perl 5 terms. In general, you do not need to worry about this. However, if you cache these objects, be aware that they do keep references to each other appropriately internally.

As well, all Parrot::PMC objects keep references to their parent interpreters for similar reasons.

METHODS ^

This class provides several methods:

AUTHOR ^

chromatic, <chromatic at wgz.org>

BUGS ^

This code might be able to detect the presence or absence of a parent interpreter and act appropriately.

This code needs to support more operations on interpreters.

Patches welcome.

Please report any bugs or feature requests to the Parrot Porters mailing list. Someday there may be a CPAN version of this code. Who knows?

COPYRIGHT & LICENSE ^

Copyright (C) 2006-2008, Parrot Foundation / chromatic.

This program is free software; you can redistribute it and/or modify it under the same terms as Parrot itself.