The current scheme of PMC instantiation works mostly fine for scalars and other simple types, but it's a bit limited. It allows only one initializer (see init_pmc in docs/pdds/pdd02_vtables.pod).

Further PMC and "real object" instantiation shouldn't differ in syntax.

Here is a summary what we currently have:

.sub main @MAIN
    $P0 = new Integer   # known type

    $P1 = new Ref, $P0  # same with initializer

    $I0 = find_type "Integer"
    $P1 = new $I0       # dynamic type or object

    .local NCI clas
    clas = global "Py_int"  # with parrot --python foo.imc
    $P0 = "0x2a"
    $P2 = clas($P0)     # the pythonic way

    clas = getclass "PerlInt"  # similar to getting the global
    .local NCI newf
    newf = global "__new__"
    $P0 = "0x2a"
    $P2 = newf(clas, $P0)     # the "new" pythonic way
.end

Perl6 seems to favor a scheme similar to the last one, something like:

    $P2 = clas."new"($P0)

Python classes and types also have a "__new__" property, so that both schemes end up as the same, namely as a class method.

Anyway the advantage of the latter two methods is obviously that the constructors can take arbitrary initializer arguments like any other function call.

Finally we must be able to override the instantiation. Parrot seems to have the "CONSTRUCT" property for that[1]. But I can imagine that a C<new> vtable [2] would work as well.

Comments welcome,
leo

[1] if that's supposed to do instantiation, the code in objects.c is bogus.

[2] see e.g. invoke() in classes/perlint.pmc



Reply via email to