Skip to content

Commit

Permalink
Merge branch 'master' of github.com:parrot/parrot
Browse files Browse the repository at this point in the history
  • Loading branch information
petdance committed Jan 6, 2011
2 parents 91e3883 + e588ed8 commit 2369288
Show file tree
Hide file tree
Showing 12 changed files with 881 additions and 61 deletions.
3 changes: 3 additions & 0 deletions MANIFEST
Expand Up @@ -1393,9 +1393,11 @@ src/pmc/orderedhashiterator.pmc []
src/pmc/packfile.pmc []
src/pmc/packfileannotation.pmc []
src/pmc/packfileannotations.pmc []
src/pmc/packfilebytecodesegment.pmc []
src/pmc/packfileconstanttable.pmc []
src/pmc/packfiledebug.pmc []
src/pmc/packfiledirectory.pmc []
src/pmc/packfileopmap.pmc []
src/pmc/packfilerawsegment.pmc []
src/pmc/packfilesegment.pmc []
src/pmc/parrotinterpreter.pmc []
Expand Down Expand Up @@ -1897,6 +1899,7 @@ t/pmc/packfileannotation.t [test]
t/pmc/packfileannotations.t [test]
t/pmc/packfileconstanttable.t [test]
t/pmc/packfiledirectory.t [test]
t/pmc/packfileopmap.t [test]
t/pmc/packfilerawsegment.t [test]
t/pmc/packfilesegment.t [test]
t/pmc/parrotclass.t [test]
Expand Down
59 changes: 20 additions & 39 deletions examples/pir/make_hello_pbc.pir
@@ -1,7 +1,7 @@
#Copyright (C) 2009, Parrot Foundation.
# Sample creating of "Hello World" program using Packfile PMCs.
.sub 'main'
.local pmc pf, pfdir, pffixup, pfbc, pfconst, oplib
.local pmc pf, pfdir, pfbc, pfconst, oplib

# Hello World is something like
# .sub 'hello'
Expand All @@ -15,43 +15,34 @@
pfdir = pf.'get_directory'()

# We need some constants
# Interpreter.
pfconst = new 'PackfileConstantTable'
$P0 = getinterp
pfconst[0] = $P0

# Empty FIA for handling returns from "hello"
$P0 = new 'FixedIntegerArray'
pfconst[1] = $P0

# "Hello World" string
pfconst[2] = "Hello World"

# "hello" is function name
pfconst[3] = "hello"

# "hello.pir" is our pir file which we are "compiling"
pfconst[4] = "hello.pir"

# We will need Sub PMC as well but will deal with it later.
# Add PackfileConstantTable into directory.
pfdir["CONSTANTS_hello.pir"] = pfconst

# Generate bytecode
pfbc = new 'PackfileRawSegment'
oplib = new 'OpLib'
pfbc = new 'PackfileBytecodeSegment'
.local pmc op

# Here is our function
$I0 = oplib['say_sc']
pfbc[0] = $I0
pfbc[1] = 0x002 # constant id.
op = new ['ResizablePMCArray']
op[0] = 'say_sc'
$I0 = pfconst.'get_or_create_constant'("Hello, World")
op[1] = $I0
push pfbc, op

$I0 = oplib['set_returns_pc']
pfbc[2] = $I0
pfbc[3] = 0x001 # id of FIA
# Empty FIA for handling returns from "hello"
$P0 = new 'FixedIntegerArray'
op = new ['ResizablePMCArray']
op[0] = 'set_returns_pc'
$I0 = pfconst.'get_or_create_constant'($P0)
op[1] = $I0
push pfbc, op

$I0 = oplib['returncc']
pfbc[4] = $I0
op = new ['ResizablePMCArray']
op[0] = 'returncc'
push pfbc, op

# Store bytecode
pfdir['BYTECODE_hello.pir'] = pfbc
Expand All @@ -68,19 +59,9 @@
$P0['vtable_index'] = -1 # It required to store sub in namespace

$P1 = new 'Sub', $P0

# and store it in PackfileConstantTable
pfconst[5] = $P1

# Dark magik. Create Fixup for Sub.
pffixup = new 'PackfileFixupTable'
# Add it to Directory now because adding FixupEntries require Directory
pfdir["FIXUP_hello.pir"] = pffixup

$P1 = new 'PackfileFixupEntry'
$P1 = 'hello'
$P1.'set_type'(1)
$P1 = 5 # offset
pffixup[0] = $P1
push pfconst, $P1

# Now pack Packfile and save it
$S0 = pf
Expand Down
21 changes: 17 additions & 4 deletions src/pmc/oplib.pmc
Expand Up @@ -64,8 +64,6 @@ pmclass OpLib auto_attrs {

GET_ATTR_oplib(INTERP, SELF, oplib);
num = oplib->_op_code(INTERP, cstr, 1);
if (num == -1)
num = oplib->_op_code(INTERP, cstr, 0);

Parrot_str_free_cstring(cstr);
return num;
Expand Down Expand Up @@ -115,8 +113,13 @@ pmclass OpLib auto_attrs {
return STATICSELF.elements();
}

METHOD op_family(STRING *shortname)
{
VTABLE void* get_pointer() {
op_lib_t *oplib;
GET_ATTR_oplib(INTERP, SELF, oplib);
return oplib;
}

METHOD op_family(STRING *shortname) {
char * const sname = Parrot_str_to_cstring(INTERP, shortname);
op_lib_t *oplib;
op_info_t *table;
Expand All @@ -135,6 +138,16 @@ pmclass OpLib auto_attrs {
Parrot_str_free_cstring(sname);
RETURN(PMC *result);
}

METHOD version() {
op_lib_t *oplib;
PMC *version_array = Parrot_pmc_new(INTERP, enum_class_ResizableIntegerArray);
GET_ATTR_oplib(INTERP, SELF, oplib);
VTABLE_push_integer(INTERP, version_array, oplib->major_version);
VTABLE_push_integer(INTERP, version_array, oplib->minor_version);
VTABLE_push_integer(INTERP, version_array, oplib->patch_version);
RETURN(PMC *version_array);
}
}

/*
Expand Down
18 changes: 9 additions & 9 deletions src/pmc/packfile.pmc
Expand Up @@ -94,15 +94,15 @@ copy_packfile_header(PARROT_INTERP, ARGMOD(PMC *self), ARGIN(PackFile *pf))
}

pmclass Packfile auto_attrs {
ATTR INTVAL wordsize;
ATTR INTVAL byteorder;
ATTR INTVAL fptype;
ATTR INTVAL version_major;
ATTR INTVAL version_minor;
ATTR INTVAL version_patch;
ATTR INTVAL bytecode_major;
ATTR INTVAL bytecode_minor;
ATTR INTVAL uuid_type;
ATTR INTVAL wordsize;
ATTR INTVAL byteorder;
ATTR INTVAL fptype;
ATTR INTVAL version_major;
ATTR INTVAL version_minor;
ATTR INTVAL version_patch;
ATTR INTVAL bytecode_major;
ATTR INTVAL bytecode_minor;
ATTR INTVAL uuid_type;
ATTR STRING *uuid;

ATTR PMC *directory;
Expand Down

0 comments on commit 2369288

Please sign in to comment.