Source

spix / Spix / Match.pir

# Copyright (C) 2010, Parrot Foundation.

.sub 'onload' :load
    .local pmc class
    class = newclass ['Spix';'Match']
    addattribute class, 'children'
    addattribute class, 'attrs'
.end

.namespace ['Spix';'Match']

.sub 'init_pmc' :vtable :method
    .param pmc options
    setattribute self, 'attrs', options
.end

.sub 'children' :method
    .param pmc value :optional
    .param int got_value :opt_flag

    if got_value goto setvalue
    $P0 = getattribute self, 'children'
    .return ($P0)
  setvalue:
    setattribute self, 'children', value
    .return (value)
.end

.sub 'attrs' :method
    .param pmc value :optional
    .param int got_value :opt_flag

    if got_value goto setvalue
    $P0 = getattribute self, 'attrs'
    .return ($P0)
  setvalue:
    setattribute self, 'attrs', value
    .return (value)
.end

.sub 'src' :method
    .param pmc value :optional
    .param int got_value :opt_flag

    if got_value goto setvalue
    $P0 = getattribute self, 'attrs'
    $P1 = $P0['src']
    if null $P1 goto empty_string
    .return ($P1)
  setvalue:
    $P0 = getattribute self, 'attrs'
    $P0['src'] = value
    .return (value)
  empty_string:
    .return ('')
.end

.sub "__dump" :method
    .param pmc dumper
    .param string label
    .local string indent, subindent
    .local pmc it, val
    .local string key
    .local pmc hash, array
    .local int hasderivs

    (subindent, indent) = dumper."newIndent"()
    print "=> "
    hasderivs = 0
    hash = self.'attrs'()
    if_null hash, dump_array
    it = iter hash
  dump_hash_1:
    unless it goto dump_array
    if hasderivs goto dump_hash_2
    print " {"
    hasderivs = 1
  dump_hash_2:
    print "\n"
    print subindent
    key = shift it
    val = hash[key]
    print "<"
    print key
    print "> => "
    dumper."dump"(label, val)
    goto dump_hash_1
  dump_array:
    array = self.'children'()
    if_null array, dump_end
    $I1 = elements array
    $I0 = 0
  dump_array_1:
    if $I0 >= $I1 goto dump_end
    if hasderivs goto dump_array_2
    print " {"
    hasderivs = 1
  dump_array_2:
    print "\n"
    print subindent
    val = array[$I0]
    print "["
    print $I0
    print "] => "
    dumper."dump"(label, val)
    inc $I0
    goto dump_array_1
  dump_end:
    unless hasderivs goto end
    print "\n"
    print indent
    print "}"
  end:
    dumper."deleteIndent"()
.end
# Local Variables:
#   mode: pir
#   fill-column: 100
# End:
# vim: expandtab shiftwidth=4 ft=pir: