Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

autrijus (1505)

autrijus
  (email not shown publicly)
http://pugs.blogs.com/

Journal of autrijus (1505)

Thursday August 04, 2005
02:19 PM

Day 179 (r6074): Fun with Perl 6's Theology, err, MetaModel.

[ #26097 ]
$work took most of my time today. However, late tonight I caught Stevan on #perl6, and he guided me through his amazing self-hosting implementation of Perl 6's meta-object protocol in Perl 5, so I can port it to Haskell for the new PIL runcore.

At the same time, iblech is merging the JavaScript version of metamodel into the PIL2JS runtime, so that backend can have a reasonable chance of passing (and unexpectedly succeeding) t/oo/ tests.

Meta-object protocol is a lot of fun. Thanks to Haskell's lazy evaluation and the builtin yadayada operator (i.e. undefined), I churned out the first cut of primitive metaobjects relatively quickly.

To aid my understanding, I drew in lots of Gnosticism metaphors. For example, the demiurge below is the original Perl6::MetaClass, the root of everything, with its metaclass defined as an instance of itself:

-- Perl6::MetaClass - &_build_meta line 1
-- First metaclass by parthenogenesis
demiurge :: Object
demiurge = MkObject{ objClass = cls, objData = dat }
    where
    (fld, dat) = splitMap (gnosis $ MkName undef) -- no $.name
    cls = MkClass{ clsMeta = demiurge, clsFields = fld }

After it consumed the bare-bones class definition in gnosis, we build the archetypical Perl6::Object metaclass from that; it's called pneuma, with its class definition defined in logos, which covers the class methods (new, bless, CREATE, isa, can) and instance methods (BUILDALL, DESTROYALL, isa, can).

Then we use the _build_meta helper -- conveniently named metamorph in my current code -- to augment demiurge with primitive, internal-only methods (BUILD, is_a, _merge, _create_accessor), plus accessors to the attribute and method tables. The code that does this reads:

-- Bootstrapped MetaClass - suitable for applying to environment
theos :: Object
theos = metamorph demiurge

The final task of this first-step bootstrapping, genesis, merely declares that theos has pneuma as a superclass; that is, the Perl6 MetaClass is itself a Perl6 Object, fully exposed to the userland. Using this as a base, all primitive runtime constructs can automatically appear as well-behaving objects. But that's another topic for another day...

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.
  • Gnosticism in the text is rendered Gnoticism.

    It is lovely seeing all these powerful words inspiring (pneuma) life. But this is only the created life of the flesh (and you are aiming higher than this; Perl is intended to enrich the spirit also: the rhema that complements the logos). There is more.

    He was with God in the beginning.
    Through him all things were made; without him nothing was made that has been made.
    In him was life, and that life was the light of men.