Skip to content

Instantly share code, notes, and snippets.

@jnthn
Created October 29, 2011 21:01
Show Gist options
  • Save jnthn/1325090 to your computer and use it in GitHub Desktop.
Save jnthn/1325090 to your computer and use it in GitHub Desktop.

A New REPR API

If anything, this is a simplification.

type_object_for(HOW)

This one stays just the same as before; it's the operation that creates an s-table, a type object and ties everything together.

allocate(OBJECT)

This partially replaces instance_of, but it only does the memory allocation portion of the work. We'll also need it for auto-boxing and cloning. The object passed is most likely a type object, but could be any instance; it's the s-table that matters usually.

initialize(STABLE, DATA)

Used to initialize the body of an object representing the type describe by the specified s-table. DATA points to the body. It may recursively call initialize for any flattened objects.

copy_to(STABLE, SRCDATA, DESTDATA)

For the given type, copies the object data from the source memory location to the destination one. Note that it may actually be more involved than a straightforward bit of copying - what's important is that the representation knows about that. Once again, it may have to call copy_to recursively on representations of any flattened objects in its body.

defined(OBJECT)

Is the object, from the representation's point of view, defined (that is, an instance) or not (that is, a type object)? This also stays the same. It only makes sense to ask this of a complete object, so it need not change.

get_attribute_boxed(STABLE, DATA, CLASSHANDLE, NAME, HINT)

Returns the attribute value as an object. For non-flattened objects - that is, reference types - this just returns the object stored in the attribute. For the flattened case, this will auto-box (an allocate followed by a copy_to).

get_attribute_ref(STABLE, DATA, CLASSHANDLE, NAME, HINT)

Gets the memory address of an attribute within an object. Anything doing this presumably knows quite a bit about the type of the attribute. This subsumes the int, num and str variants of get_attribute, and also works out well for any flattened objects. Note that any consumer of this is responsible for making sure the reference lasts no longer than the object it was obtained from.

bind_attribute_boxed(STABLE, DATA, CLASSHANDLE, NAME, HINT, VALUE)

Binds an attribute. If it's a reference type attribute, this just simply sets the value in place. If instead it's some other flattened in representation, then the value should be a boxed form of the data we want to store.

bind_attribute_ref(STABLE, DATA, CLASSHANDLE, NAME, HINT, VALUE_REF)

Binds a flattened in attribute to the value at the passed reference. Like with the get_attribute_ref function, presumably the thing calling this knows about the type of the attribute it is supplying data for. copy_to will be used to copy the data in to place.

is_attribute_initialized(STABLE, DATA, CLASSHANDLE, NAME, HINT)

Mostly the same, apart from the API changed to split it to get s-table and data, like the other attribute related operations.

get_[int|num|str](STABLE, DATA)

Stay the same, apart from the s-table/data split as per normal. They may also delegate, but that's entirely up to the REPR. Note that these do not get merged like the attribute ones, since they may have more coercy semantics rather than pure storage ones.

set_[int|num|str](STABLE, DATA, VALUE)

Stay the same, apart from the s-table/data split as per normal. They may also delegate, but that's entirely up to the REPR.

get_box_target_ref(STABLE, DATA, TYPE)

Sometimes, a certain attribute may be flagged as the "default" one of a certain type, which can be used in boxing-ish situations but for more complex objects. In that case, this gets the address of the attribute serving as the "box target" for the type in question.

change_type(OBJECT, NEW_TYPE)

Stays pretty much as it is. Only makes sense to do to an object as a whole.

get_storage_spec(STABLE)

Stays the same. In some ways, by taking the s-table this kind of foretold many of the things that changed in here.

gc_mark(STABLE, DATA)

Marks what's in an object, if needed. Note that it is no longer responsible for marking the s-table and serialization context pointers.

gc_free_object(OBJECT)

Frees a (top-level, never a flattened in) object. If any complex objects with parts needing freeing are embedded, this will need to call gc_cleanup for them.

gc_cleanup(STABLE, DATA)

Responsible for freeing any resources associated with an object's body. Used to clear up when one object has another complex object flattened into it.

gc_[mark|free]_repr_data(STABLE)

Renamed to say that it really does, but otherwise the same.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment