Skip to content
This repository
tree: 97aa16a4d8
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 114 lines (86 sloc) 2.496 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113

=head1 TITLE

config.pir - Access Parrot configuration data

=head1 SYNOPSIS

  .sub _some
  ...
  load_bytecode 'config.pbc'
  # store the config data into $P0
  $P0 = _config()
  # Retrieve and print a key
  $S1 = $P0["cc"]
  print "Your C compiler is "
  print $S1
  print "\n"
  ...

 .end

=head1 DESCRIPTION

config.pir is a mechanism for accessing most of the data collected by
Configure. It's roughly equivalent to Perl5's C<Config.pm> module.

At the end of a successful C<make> of Parrot, a PIR file generated by
Configure is run to put a file, F<config.fpmc>, into the library with a
frozen Hash of the configuration data. This library provides a
function, C<_config>, to unpack and return that file's data.

C<_config> does not take any parameters. It returns a single Hash
containing the data. Keys that were C<undef> in Configure contain a
null string; otherwise they contain a non-null, possibly empty, string.

Note that the behavior of that hash when writing to any value (especially
undefined values) is undefined, and may be rather funky.

=cut

.include "interpinfo.pasm"

.sub _config
    .local string prefix, conf_file
    .local pmc ex
    prefix = interpinfo .INTERPINFO_RUNTIME_PREFIX

    $S0 = concat prefix, "/runtime"

    push_eh L1
        $P0 = new 'OS'
        pop_eh

    push_eh file_not_found
        # OS.stat throws on file not found
        $P0.'stat'($S0)
        goto L1
  file_not_found:
    .get_results (ex)
    finalize ex
    # Treat it as installed parrot.
    conf_file = "@libdir@@versiondir@/include/config.fpmc"
    goto L2
  L1:
    conf_file = prefix . "/runtime/parrot/include/config.fpmc"
  L2:
    pop_eh

    .local pmc CONF
    CONF = new 'FileHandle'
    push_eh error
    CONF.'encoding'('binary')
    .local string image
    image = CONF.'readall'(conf_file)
    pop_eh

    .local pmc conf_hash
    thaw conf_hash, image

    .local pmc one
    one = new 'Integer'
    one = 1
    setprop conf_hash, '_ro', one

    .return( conf_hash )

error:
    .get_results (ex)
    $S0 = "Can't read '"
    $S0 .= conf_file
    $S0 .= "' : "
    $S1 = err
    $S0 .= $S1
    ex = $S0
    rethrow ex
.end

=head1 AUTHOR

Brent Royal-Gordon E<lt>brent@brentdax.comE<gt> is the author and maintainer.
Please send patches and suggestions to the Parrot porters mailing list.

=head1 COPYRIGHT

Copyright (C) 2004-2009, Parrot Foundation.

=cut

# Local Variables:
# mode: pir
# fill-column: 100
# End:
# vim: expandtab shiftwidth=4 ft=pir:
Something went wrong with that request. Please try again.