Skip to content

Instantly share code, notes, and snippets.

@mildred
Created January 13, 2012 18:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mildred/1607820 to your computer and use it in GitHub Desktop.
Save mildred/1607820 to your computer and use it in GitHub Desktop.
Io Parrot again
#IoObject method(args)
# $1 = VTABLE(IoObject).get(IoObject, "method")
# $2 = VTABLE(IoObject).get($1, "isActivable", "0")
# $3 = $1 0#perform(args) [if $2]
# VTABLE(IoObject).call($1, "perform", args)
# $3 = $2 [otherwise]
IoObject view#method(args)
$1 = VTABLE(IoObject).get(IoObject, "method", "view")
return VTABLE($1).call($1, IoObject, args)
[$1 is IoBuiltin]
... do the built-in work ...
[$1 is IoObject]
$2 = VTABLE(IoObject).get($1, "isActivable", "0")
[if not $2]
return $1
[if $2]
$3 = VTABLE(IoObject).get($1, "perform", "0")
return VTABLE($3).call($3, $1, args)
Implementation
==============
VTABLE(IoObject).get($pmc, $slotName, $slotView)
return the slot object or nil
VTABLE(IoObject).call($pmc, $args...)
$1 = VTABLE(IoObject).get($pmc, "isActivable", "0")
[if $1]
$2 = VTABLE(IoObject).get($pmc, "perform", "0")
$3 = VTABLE($2).call($2, $pmc, $args...)
[unless $1]
return $pmc
pmclass IoBuiltin is IoObject
VTABLE(IoBuiltin).call($pmc, $self, $args...)
[builtin is 'Method perform']
$1 = VTABLE(IoBuiltin).get($pmc, "code", ???)
execute code $1 in context of $self
[...]
...
Normal Io
=========
method(args)
$1 = $self getSlot("method")
$1 = $self getSlot("forward") [if not $1]
$2 = $1 getSlot("isActivable")
return $1 [if not $2]
return $1 performOn($self, args) [if $2]
$3 = $1 getSlot("performOn")
$4 = $3 getSlot("isActivable")
return $3 [if not $4]
return $3 performOn($1, ($self, args)) [if $4]
no recursion because performOn is a CFunction
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment