Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Add a way to give an SC a friendly description.
  • Loading branch information
jnthn committed Jul 26, 2011
1 parent e9244ec commit 3279ea7
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 8 deletions.
12 changes: 6 additions & 6 deletions src/HLL/SerializationContextBuilder.pm
Expand Up @@ -57,18 +57,18 @@ class HLL::Compiler::SerializationContextBuilder {
# Other SCs that we are dependent on (maps handle to SC).
has %!dependencies;

# XXX Fix BUILD...
method new(:$handle!) {
method new(:$handle!, :$description = '<unknown>') {
my $obj := self.CREATE();
$obj.BUILD(:handle($handle));
$obj.BUILD(:handle($handle), :description($description));
$obj
}

method BUILD(:$handle) {
$!sc := pir::nqp_create_sc__PS($handle);
$!handle := $handle;
method BUILD(:$handle!, :$description!) {
$!sc := pir::nqp_create_sc__PS($handle);
$!handle := $handle;
%!addr_to_slot := pir::new('Hash');
@!event_stream := pir::new('ResizablePMCArray');
$!sc.set_description($description);
}

# Gets the slot for a given object. Dies if it is not in the context.
Expand Down
20 changes: 18 additions & 2 deletions src/pmc/serializationcontext.pmc
Expand Up @@ -5,9 +5,12 @@ pmclass SerializationContext auto_attrs dynpmc group nqp {
/* The handle of this SC. */
ATTR STRING *handle;

/* The set of objects that live in this SC. */
/* The root set of objects that live in this SC. */
ATTR PMC *root_objects;

/* Description (probably the file name) if any. */
ATTR STRING *description;

VTABLE void init() {
PMC *root_objects = pmc_new(interp, enum_class_ResizablePMCArray);
SETATTR_SerializationContext_root_objects(interp, SELF, root_objects);
Expand All @@ -20,11 +23,13 @@ pmclass SerializationContext auto_attrs dynpmc group nqp {

VTABLE void mark() {
PMC *root_objects;
STRING *handle;
STRING *handle, *description;
GETATTR_SerializationContext_root_objects(interp, SELF, root_objects);
Parrot_gc_mark_PMC_alive(INTERP, root_objects);
GETATTR_SerializationContext_handle(interp, SELF, handle);
Parrot_gc_mark_STRING_alive(INTERP, handle);
GETATTR_SerializationContext_description(interp, SELF, description);
Parrot_gc_mark_STRING_alive(INTERP, description);
}

VTABLE PMC* get_pmc_keyed_int(INTVAL idx) {
Expand Down Expand Up @@ -65,6 +70,17 @@ pmclass SerializationContext auto_attrs dynpmc group nqp {
RETURN (STRING* handle);
}

METHOD set_description(STRING *description) {
SETATTR_SerializationContext_description(interp, SELF, description);
RETURN (STRING* description);
}

METHOD STRING* description() {
STRING *description;
GETATTR_SerializationContext_description(interp, SELF, description);
RETURN (STRING* description);
}

METHOD INTVAL slot_index_for(PMC *obj) {
/* This is kinda stupid, but it'll do for now. */
PMC *root_objects;
Expand Down

0 comments on commit 3279ea7

Please sign in to comment.