Author: fperrad
Date: Thu Mar 27 03:44:08 2008
New Revision: 26577
Added:
trunk/languages/lua/src/POST.pir (contents, props changed)
Modified:
trunk/languages/lua/config/makefiles/root.in
trunk/languages/lua/doc/status.pod
trunk/languages/lua/src/PASTGrammar.tg
trunk/languages/lua/src/POSTGrammar.tg
trunk/languages/lua/src/lua51.pir
Log:
[Lua] PAST-pm deprecation
- replace PAST-pm/PAST by PCT/PAST
- replace PAST-pm/POST by Lua/POST (a private copy of PAST-pm/POST)
Modified: trunk/languages/lua/config/makefiles/root.in
==============================================================================
--- trunk/languages/lua/config/makefiles/root.in (original)
+++ trunk/languages/lua/config/makefiles/root.in Thu Mar 27 03:44:08 2008
@@ -116,7 +116,7 @@
src/POSTGrammar_gen.pir: src/POSTGrammar.tg
$(TGE) --output=src/POSTGrammar_gen.pir src/POSTGrammar.tg
-lua.pbc: lua.pir src/lua51.pir src/lua51_gen.pir src/PASTGrammar_gen.pir
src/POSTGrammar_gen.pir $(LIB_SRCS)
+lua.pbc: lua.pir src/lua51.pir src/lua51_gen.pir src/PASTGrammar_gen.pir
src/POSTGrammar_gen.pir src/POST.pir $(LIB_SRCS)
$(PARROT) -o lua.pbc --output-pbc lua.pir
[EMAIL PROTECTED]@: lua.pbc
Modified: trunk/languages/lua/doc/status.pod
==============================================================================
--- trunk/languages/lua/doc/status.pod (original)
+++ trunk/languages/lua/doc/status.pod Thu Mar 27 03:44:08 2008
@@ -43,10 +43,13 @@
Two stages of tree transformation are used
F<languages/lua/src/PASTGrammar.tg> & F<languages/lua/src/POSTGrammar.tg>.
-=item PAST-pm
+=item PAST
-The AST is represented with F<compilers/past-pm/PAST/Node.pir> and the OST
-with F<compilers/past-pm/POST/Node.pir>.
+The AST is represented with F<compilers/pct/src/PAST/Node.pir>.
+
+=item POST
+
+The OST is represented with F<languages/lua/src/POST.pir>.
=item HLLCompiler
Modified: trunk/languages/lua/src/PASTGrammar.tg
==============================================================================
--- trunk/languages/lua/src/PASTGrammar.tg (original)
+++ trunk/languages/lua/src/PASTGrammar.tg Thu Mar 27 03:44:08 2008
@@ -1,4 +1,4 @@
-# Copyright (C) 2006-2007, The Perl Foundation.
+# Copyright (C) 2006-2008, The Perl Foundation.
# $Id$
=head1 NAME
@@ -31,8 +31,10 @@
$I0 = symbtab
if $I0 goto L1
.local pmc arg
- arg = past.'new'('PAST::Var', 'node'=>node, 'name'=>'vararg',
'scope'=>'parameter', 'isslurpy'=>1)
- .return past.'new'('PAST::Block', arg, past, 'node'=>node, 'name'=>'&main')
+ $P0 = get_hll_global ['PAST'], 'Var'
+ arg = $P0.'new'('node'=>node, 'name'=>'vararg', 'scope'=>'parameter',
'slurpy'=>1)
+ $P0 = get_hll_global ['PAST'], 'Block'
+ .return $P0.'new'(arg, past, 'node'=>node, 'name'=>'&main')
L1:
$S1 = $I0
$S0 = "symbol table (" . $S1
@@ -43,8 +45,8 @@
transform past (Lua::Grammar::block) :language('PIR') {
.local pmc past
- new past, 'PAST::Stmts'
- past.'init'('node'=>node)
+ $P0 = get_hll_global ['PAST'], 'Stmts'
+ past = $P0.'new'('node'=>node)
$P0 = node['statement']
if null $P0 goto L1
.local pmc iter, cpast
@@ -96,7 +98,8 @@
.local pmc past, cpast, blk
$P0 = node['block']
blk = tree.'get'('past', $P0, 'Lua::Grammar::block')
- past = expr.'new'('PAST::Op', expr, blk, 'node'=>node, 'pasttype'=>'if')
+ $P0 = get_hll_global ['PAST'], 'Op'
+ past = $P0.'new'(expr, blk, 'node'=>node, 'pasttype'=>'if')
cpast = past
$P0 = node['elseif_block']
if null $P0 goto L1
@@ -132,7 +135,8 @@
.local pmc blk
$P0 = node['block']
blk = tree.'get'('past', $P0, 'Lua::Grammar::block')
- .return expr.'new'('PAST::Op', expr, blk, 'node'=>node, 'pasttype'=>'if')
+ $P0 = get_hll_global ['PAST'], 'Op'
+ .return $P0.'new'(expr, blk, 'node'=>node, 'pasttype'=>'if')
}
@@ -150,7 +154,8 @@
$P0 = node['block']
blk = tree.'get'('past', $P0, 'Lua::Grammar::block')
dec looplevel
- .return expr.'new'('PAST::Op', expr, blk, 'node'=>node,
'pasttype'=>'while')
+ $P0 = get_hll_global ['PAST'], 'Op'
+ .return $P0.'new'(expr, blk, 'node'=>node, 'pasttype'=>'while')
}
@@ -168,7 +173,8 @@
$P0 = node['expression']
expr = tree.'get'('past', $P0, 'Lua::Grammar::expression')
dec looplevel
- .return expr.'new'('PAST::Op', blk, expr, 'node'=>node,
'pasttype'=>'repeat')
+ $P0 = get_hll_global ['PAST'], 'Op'
+ .return $P0.'new'(blk, expr, 'node'=>node, 'pasttype'=>'repeat')
}
@@ -198,9 +204,9 @@
$P0 = node['Name']
$S0 = $P0.'result_object'()
.local pmc name
- new name, 'PAST::Var'
$S1 = symbtab.'insert'($S0)
- name.'init'('node'=>node, 'name'=>$S1, 'scope'=>'lexical', 'ismy'=>1,
'islvalue'=>1)
+ $P0 = get_hll_global ['PAST'], 'Var'
+ name = $P0.'new'('node'=>node, 'name'=>$S1, 'scope'=>'lexical',
'isdecl'=>1, 'lvalue'=>1)
.local pmc explist
new explist, 'ResizablePMCArray'
$P0 = node['expression']
@@ -215,10 +221,12 @@
goto L1
L2:
unless $I0 < 3 goto L3
- expr = name.'new'('PAST::Val', 'node'=>node, 'vtype'=>'LuaNumber',
'name'=>'1')
+ $P0 = get_hll_global ['PAST'], 'Val'
+ expr = $P0.'new'('node'=>node, 'name'=>'LuaNumber', 'value'=>'1')
push explist, expr
L3:
- .return name.'new'('PAST::Op', name, explist, 'node'=>node,
'pasttype'=>'fornum')
+ $P0 = get_hll_global ['PAST'], 'Op'
+ .return $P0.'new'(name, explist, 'node'=>node, 'pasttype'=>'fornum')
}
@@ -236,18 +244,17 @@
unless iter goto L2
$P0 = shift iter
$S0 = $P0.'result_object'()
- new cpast, 'PAST::Var'
$S1 = symbtab.'insert'($S0)
- cpast.'init'('node'=>node, 'name'=>$S1, 'scope'=>'lexical', 'ismy'=>1,
'islvalue'=>1)
+ $P0 = get_hll_global ['PAST'], 'Var'
+ cpast = $P0.'new'('node'=>node, 'name'=>$S1, 'scope'=>'lexical',
'isdecl'=>1, 'lvalue'=>1)
push namelist, cpast
goto L1
L2:
$P0 = node['expression_list']
.local pmc explist
explist = tree.'get'('explist', $P0, 'Lua::Grammar::expression_list')
- .local pmc past
- new past, 'PAST::Op'
- .return past.'init'(namelist, explist, 'node'=>node, 'pasttype'=>'forlist')
+ $P0 = get_hll_global ['PAST'], 'Op'
+ .return $P0.'new'(namelist, explist, 'node'=>node, 'pasttype'=>'forlist')
}
@@ -280,15 +287,14 @@
unless iter goto L4
$P0 = shift iter
$S0 = $P0.'result_object'()
- new cpast, 'PAST::Var'
$S1 = symbtab.'insert'($S0)
- cpast.'init'('node'=>node, 'name'=>$S1, 'scope'=>'lexical', 'ismy'=>1,
'islvalue'=>1)
+ $P0 = get_hll_global ['PAST'], 'Var'
+ cpast = $P0.'new'('node'=>node, 'name'=>$S1, 'scope'=>'lexical',
'isdecl'=>1, 'lvalue'=>1)
push namelist, cpast
goto L3
L4:
- .local pmc past
- new past, 'PAST::Op'
- .return past.'init'(namelist, explist, 'node'=>node,
'pasttype'=>'assignlist')
+ $P0 = get_hll_global ['PAST'], 'Op'
+ .return $P0.'new'(namelist, explist, 'node'=>node,
'pasttype'=>'assignlist')
}
@@ -296,30 +302,31 @@
.local pmc symbtab
symbtab = get_hll_global ['Lua::PAST'], '$symbtab'
.local pmc var
- new var, 'PAST::Var'
$P0 = node['Name']
$S0 = $P0.'result_object'()
$S1 = symbtab.'insert'($S0)
- var.'init'('PAST::Var', 'node'=>$P0, 'name'=>$S1, 'scope'=>'lexical',
'ismy'=>1, 'islvalue'=>1)
+ $P1 = get_hll_global ['PAST'], 'Var'
+ var = $P1.'new'('node'=>$P0, 'name'=>$S1, 'scope'=>'lexical', 'isdecl'=>1,
'lvalue'=>1)
.local pmc past
$P0 = node['function_body']
past = tree.'get'('past', $P0, 'Lua::Grammar::function_body')
past.'name'($S0)
- .return past.'new'('PAST::Op', var, past, 'node'=>node,
'pasttype'=>'assign')
+ $P0 = get_hll_global ['PAST'], 'Op'
+ $P1 = $P0.'new'(var, past, 'node'=>node, 'pasttype'=>'assign')
+ .return ($P1)
}
transform past (Lua::Grammar::return_statement) :language('PIR') {
- .local pmc past
- new past, 'PAST::Op'
+ $P1 = get_hll_global ['PAST'], 'Op'
$P0 = node['expression_list']
if null $P0 goto L1
.local pmc explist
$P0 = shift $P0
explist = tree.'get'('explist', $P0, 'Lua::Grammar::expression_list')
- .return past.'init'(explist :flat, 'node'=>node, 'pasttype'=>'return')
+ .return $P1.'new'(explist :flat, 'node'=>node, 'pasttype'=>'return')
L1:
- .return past.'init'('node'=>node, 'pasttype'=>'return')
+ .return $P1.'new'('node'=>node, 'pasttype'=>'return')
}
@@ -327,9 +334,8 @@
.local pmc looplevel
looplevel = get_hll_global ['Lua::PAST'], '$looplevel'
if looplevel <= 0 goto L1
- .local pmc past
- new past, 'PAST::Op'
- .return past.'init'('node'=>node, 'pasttype'=>'break')
+ $P0 = get_hll_global ['PAST'], 'Op'
+ .return $P0.'new'('node'=>node, 'pasttype'=>'break')
L1:
node.'syntaxerror'("no loop to break")
}
@@ -348,11 +354,10 @@
.local pmc expr
$P0 = node['primary_expression']
expr = tree.'get'('past', $P0, 'Lua::Grammar::primary_expression')
- expr.'islvalue'(1)
+ expr.'lvalue'(1)
unshift varlist, expr
- .local pmc past
- new past, 'PAST::Op'
- .return past.'init'(varlist, explist, 'node'=>node,
'pasttype'=>'assignlist')
+ $P0 = get_hll_global ['PAST'], 'Op'
+ .return $P0.'new'(varlist, explist, 'node'=>node, 'pasttype'=>'assignlist')
}
@@ -368,7 +373,7 @@
.local pmc expr
$P0 = node['primary_expression']
expr = tree.'get'('past', $P0, 'Lua::Grammar::primary_expression')
- expr.'islvalue'(1)
+ expr.'lvalue'(1)
unshift varlist, expr
.return (varlist)
}
@@ -419,16 +424,17 @@
$S0 = $P0.'result_object'()
$I0 = index $S0, ':'
if $I0 < 0 goto L1
- new past, 'PAST::Var'
+ $P1 = get_hll_global ['PAST'], 'Var'
$S1 = symbtab.'insert'('self')
- past.'init'('node'=>$P0, 'name'=>$S1, 'scope'=>'parameter')
+ past = $P1.'new'('node'=>$P0, 'name'=>$S1, 'scope'=>'parameter')
set_hll_global ['Lua::PAST'], '$?self', past
L1:
$S0 = tree.'get'('Name', $P0, 'Lua::Grammar::functionname')
$P0 = node['function_body']
past = tree.'get'('past', $P0, 'Lua::Grammar::function_body')
past.'name'($S0)
- .return past.'new'('PAST::Op', var, past, 'node'=>node,
'pasttype'=>'assign')
+ $P0 = get_hll_global ['PAST'], 'Op'
+ .return $P0.'new'(var, past, 'node'=>node, 'pasttype'=>'assign')
}
@@ -461,23 +467,25 @@
$P0 = shift iter
$S0 = $P0.'result_object'()
.local pmc past
- new past, 'PAST::Var'
+ $P0 = get_hll_global ['PAST'], 'Var'
($I0, $S1) = symbtab.'lookup'($S0)
unless $I0 goto L1
- past.'init'('node'=>node, 'name'=>$S1, 'scope'=>'lexical')
+ past = $P0.'new'('node'=>node, 'name'=>$S1, 'scope'=>'lexical')
goto L2
L1:
- past.'init'('node'=>node, 'name'=>$S0, 'scope'=>'package')
+ past = $P0.'new'('node'=>node, 'name'=>$S0, 'scope'=>'package')
L2:
unless iter goto L3
$P0 = shift iter
$S0 = $P0.'result_object'()
.local pmc key
- key = past.'new'('PAST::Val', 'node'=>$P0, 'vtype'=>'key', 'name'=>$S0)
- past = past.'new'('PAST::Var', past, key, 'node'=>node, 'scope'=>'keyed')
+ $P1 = get_hll_global ['PAST'], 'Val'
+ key = $P1.'new'('node'=>$P0, 'name'=>'key', 'value'=>$S0)
+ $P0 = get_hll_global ['PAST'], 'Var'
+ past = $P0.'new'(past, key, 'node'=>node, 'scope'=>'keyed')
goto L2
L3:
- past.'islvalue'(1)
+ past.'lvalue'(1)
.return (past)
}
@@ -506,9 +514,9 @@
unless iter goto L3
$P1 = shift iter
$S0 = $P1.'result_object'()
- new var, 'PAST::Var'
$S1 = symbtab.'insert'($S0)
- var.'init'('node'=>$P1, 'name'=>$S1, 'scope'=>'parameter')
+ $P2 = get_hll_global ['PAST'], 'Var'
+ var = $P2.'new'('node'=>$P1, 'name'=>$S1, 'scope'=>'parameter')
push parlist, var
goto L4
L3:
@@ -516,14 +524,14 @@
$I0 = 0
if null $P1 goto L2
$P1 = shift $P1
- new var, 'PAST::Var'
- var.'init'('node'=>$P1, 'name'=>'vararg', 'scope'=>'parameter',
'isslurpy'=>1)
+ $P2 = get_hll_global ['PAST'], 'Var'
+ var = $P2.'new'('node'=>$P1, 'name'=>'vararg', 'scope'=>'parameter',
'slurpy'=>1)
push parlist, var
$I0 = 1
goto L5
L2:
- new var, 'PAST::Var'
- var.'init'('node'=>$P0, 'name'=>'extra', 'scope'=>'parameter',
'isslurpy'=>1)
+ $P2 = get_hll_global ['PAST'], 'Var'
+ var = $P2.'new'('node'=>$P0, 'name'=>'extra', 'scope'=>'parameter',
'slurpy'=>1)
push parlist, var
L5:
.local pmc has_vararg
@@ -541,14 +549,15 @@
past = tree.'get'('past', $P0, 'Lua::Grammar::block')
set_hll_global ['Lua::PAST'], '$looplevel', looplevel
set_hll_global ['Lua::PAST'], '?vararg', has_vararg
- .return past.'new'('PAST::Block', parlist :flat, past, 'node'=>node)
+ $P0 = get_hll_global ['PAST'], 'Block'
+ .return $P0.'new'(parlist :flat, past, 'node'=>node)
}
transform past (Lua::Grammar::constructor) :language('PIR') {
.local pmc past
- new past, 'PAST::Val'
- past.'init'('node'=>node, 'vtype'=>'constructor')
+ $P0 = get_hll_global ['PAST'], 'Val'
+ past = $P0.'new'('node'=>node, 'name'=>'constructor')
$P0 = node['tablefieldlist']
if null $P0 goto L1
$P0 = shift $P0
@@ -592,10 +601,9 @@
transform key (Lua::Grammar::Name) :language('PIR') {
- .local pmc past
$S0 = node.'result_object'()
- new past, 'PAST::Val'
- .return past.'init'('node'=>node, 'vtype'=>'key', 'name'=>$S0)
+ $P0 = get_hll_global ['PAST'], 'Val'
+ .return $P0.'new'('node'=>node, 'name'=>'key', 'value'=>$S0)
}
@@ -643,13 +651,13 @@
optok = optable[type]
pirop = optok['pirop']
.local pmc past
- new past, 'PAST::Op'
+ $P0 = get_hll_global ['PAST'], 'Op'
if pirop == '' goto L2
- past.'init'('node'=>node, 'name'=>type, 'pasttype'=>'pirop',
'pirop'=>pirop)
+ past = $P0.'new'('node'=>node, 'name'=>type, 'pasttype'=>'pirop',
'pirop'=>pirop)
goto L3
L2:
$S0 = optok['past']
- past.'init'('node'=>node, 'name'=>type, 'pasttype'=>$S0)
+ past = $P0.'new'('node'=>node, 'name'=>type, 'pasttype'=>$S0)
L3:
$P0 = node.'get_array'()
.local pmc iter, expr
@@ -691,24 +699,29 @@
if null $P1 goto L4
.local pmc meth, obj
key = tree.'get'('key', $P1, 'Lua::Grammar::Name')
- meth = past.'new'('PAST::Var', past, key, 'node'=>node, 'scope'=>'keyed')
+ $P2 = get_hll_global ['PAST'], 'Var'
+ meth = $P2.'new'(past, key, 'node'=>node, 'scope'=>'keyed')
obj = clone past
- past = past.'new'('PAST::Op', meth, obj, args :flat, 'node'=>node,
'pasttype'=>'call')
+ $P2 = get_hll_global ['PAST'], 'Op'
+ past = $P2.'new'(meth, obj, args :flat, 'node'=>node, 'pasttype'=>'call')
goto L2
L4:
- past = past.'new'('PAST::Op', past, args :flat, 'node'=>node,
'pasttype'=>'call')
+ $P2 = get_hll_global ['PAST'], 'Op'
+ past = $P2.'new'(past, args :flat, 'node'=>node, 'pasttype'=>'call')
goto L2
L3:
$P1 = $P0['Name']
if null $P1 goto L5
key = tree.'get'('key', $P1, 'Lua::Grammar::Name')
- past = past.'new'('PAST::Var', past, key, 'node'=>node, 'scope'=>'keyed')
+ $P2 = get_hll_global ['PAST'], 'Var'
+ past = $P2.'new'(past, key, 'node'=>node, 'scope'=>'keyed')
goto L2
L5:
$P1 = $P0['index']
if null $P1 goto L6
key = tree.'get'('key', $P1, 'Lua::Grammar::index')
- past = past.'new'('PAST::Var', past, key, 'node'=>node, 'scope'=>'keyed')
+ $P2 = get_hll_global ['PAST'], 'Var'
+ past = $P2.'new'(past, key, 'node'=>node, 'scope'=>'keyed')
goto L2
L6:
internal_error("primary expression")
@@ -729,21 +742,21 @@
.local pmc past
$P0 = node['expression']
past = tree.'get'('past', $P0, 'Lua::Grammar::expression')
- .return past.'new'('PAST::Op', past, 'node'=>node,
'pasttype'=>'parenthese')
+ $P0 = get_hll_global ['PAST'], 'Op'
+ .return $P0.'new'(past, 'node'=>node, 'pasttype'=>'parenthese')
}
transform past (Lua::Grammar::Name) :language('PIR') {
.local pmc symbtab
symbtab = get_hll_global ['Lua::PAST'], '$symbtab'
- .local pmc past
- new past, 'PAST::Var'
+ $P0 = get_hll_global ['PAST'], 'Var'
$S0 = node.'result_object'()
($I0, $S1) = symbtab.'lookup'($S0)
unless $I0 goto L1
- .return past.'init'('node'=>node, 'name'=>$S1, 'scope'=>'lexical')
+ .return $P0.'new'('node'=>node, 'name'=>$S1, 'scope'=>'lexical')
L1:
- .return past.'init'('node'=>node, 'name'=>$S0, 'scope'=>'package')
+ .return $P0.'new'('node'=>node, 'name'=>$S0, 'scope'=>'package')
}
@@ -751,40 +764,35 @@
.local pmc has_vararg
has_vararg = get_hll_global ['Lua::PAST'], '?vararg'
unless has_vararg goto L1
- .local pmc past
- new past, 'PAST::Op'
- .return past.'init'('node'=>node, 'pasttype'=>'vararg')
+ $P0 = get_hll_global ['PAST'], 'Op'
+ .return $P0.'new'('node'=>node, 'pasttype'=>'vararg')
L1:
node.'syntaxerror'("cannot use '...' outside a vararg function")
}
transform past (Lua::Grammar::nil) :language('PIR') {
- .local pmc past
- new past, 'PAST::Val'
- .return past.'init'('node'=>node, 'vtype'=>'LuaNil')
+ $P0 = get_hll_global ['PAST'], 'Val'
+ .return $P0.'new'('node'=>node, 'name'=>'LuaNil')
}
transform past (Lua::Grammar::true) :language('PIR') {
- .local pmc past
- new past, 'PAST::Val'
- .return past.'init'('node'=>node, 'vtype'=>'LuaBoolean', 'name'=>1)
+ $P0 = get_hll_global ['PAST'], 'Val'
+ .return $P0.'new'('node'=>node, 'name'=>'LuaBoolean', 'value'=>1)
}
transform past (Lua::Grammar::false) :language('PIR') {
- .local pmc past
- new past, 'PAST::Val'
- .return past.'init'('node'=>node, 'vtype'=>'LuaBoolean', 'name'=>0)
+ $P0 = get_hll_global ['PAST'], 'Val'
+ .return $P0.'new'('node'=>node, 'name'=>'LuaBoolean', 'value'=>0)
}
transform past (Lua::Grammar::number) :language('PIR') {
$S0 = node.'result_object'()
- .local pmc past
- new past, 'PAST::Val'
- .return past.'init'('node'=>node, 'vtype'=>'LuaNumber', 'name'=>$S0)
+ $P0 = get_hll_global ['PAST'], 'Val'
+ .return $P0.'new'('node'=>node, 'name'=>'LuaNumber', 'value'=>$S0)
}
@@ -792,9 +800,8 @@
$S0 = node.'find_key'()
$P0 = node[$S0]
$S0 = $P0.'result_object'()
- .local pmc past
- new past, 'PAST::Val'
- .return past.'init'('node'=>node, 'vtype'=>'LuaString', 'name'=>$S0)
+ $P0 = get_hll_global ['PAST'], 'Val'
+ .return $P0.'new'('node'=>node, 'name'=>'LuaString', 'value'=>$S0)
}
=head1 AUTHORS
Added: trunk/languages/lua/src/POST.pir
==============================================================================
--- (empty file)
+++ trunk/languages/lua/src/POST.pir Thu Mar 27 03:44:08 2008
@@ -0,0 +1,876 @@
+# Copyright (C) 2008, The Perl Foundation.
+# $Id$
+
+=head1 NAME
+
+POST - Parrot opcode syntax tree
+
+=head1 DESCRIPTION
+
+This file implements the various opcode syntax tree nodes
+for compiling programs in Parrot.
+
+=cut
+
+.namespace [ 'Lua::PAST' ]
+
+.sub '__onload' :load :init
+ load_bytecode 'TGE.pbc'
+ $P0 = get_class 'TGE::Grammar'
+ $P1 = subclass $P0, 'POST::Grammar'
+
+ ## create the PAST::Node base class
+ ## XXX: Eventually we want this to be a subclass of
+ ## Capture, but as of now Capture isn't working.
+ ## So, we'll simulate it for now.
+ .local pmc base
+ load_bytecode 'Parrot/Capture_PIR.pir'
+ base = subclass 'Capture_PIR', 'Lua::PAST::Node'
+
+ .return ()
+.end
+
+=head1 PAST Node types
+
+=head2 PAST::Node
+
+C<PAST::Node> is the base class for all PAST (and POST) nodes. It's
+derived from class C<Capture>, so that it has both array and hash
+components. The array component is used to maintain a node's children,
+while the hash component contains the attributes of the node. In general
+we provide and use accessor methods for a node's attributes, instead
+of accessing the hash component directly.
+
+Every PAST node predefines C<name>, C<source>, and C<pos> attributes.
+The C<name> attribute is the node's name, if any, while C<source>
+and C<pos> are used to identify the location in the original source
+code for the node. The C<source> and C<pos> values are generally
+set by the C<node> method below.
+
+Other node attributes are generally defined by subclasses of C<PAST::Node>.
+
+=over 4
+
+=item init([child1, child2, ..., ] [attr1=>val1, attr2=>val2, ... ])
+
+Initialize a PAST node with the given children and attributes.
+Adds each child to the node (using the C<push> method, below) and
+calls the appropriate accessor method for each attribute.
+And returns the node.
+
+=cut
+
+.namespace [ 'Lua::PAST::Node' ]
+
+.sub 'init' :method
+ .param pmc children :slurpy
+ .param pmc adverbs :slurpy :named
+
+ .local pmc iter
+ iter = new .Iterator, children
+ children_loop:
+ unless iter goto children_end
+ $P0 = shift iter
+ push self, $P0
+ goto children_loop
+ children_end:
+
+ iter = new .Iterator, adverbs
+ adverbs_loop:
+ unless iter goto adverbs_end
+ $S0 = shift iter
+ $P0 = iter[$S0]
+ $P1 = find_method self, $S0
+ self.$P1($P0)
+ goto adverbs_loop
+ adverbs_end:
+ end:
+ .return (self)
+.end
+
+
+=item new(class, [child1, child2, ..., ] [attr1=>val1, attr2=>val2, ...])
+
+Create a new PAST node of type C<class> initialized with the given
+children and attributes. Returns the newly created node.
+
+=cut
+
+.sub 'new' :method
+ .param string class
+ .param pmc children :slurpy
+ .param pmc adverbs :slurpy :named
+
+ $P0 = new class
+ $P0.'init'(children :flat, 'node'=>self, adverbs :flat :named)
+ .return ($P0)
+.end
+
+
+=item push(child)
+
+Add C<child> to the end of the invocant's list of children.
+
+=cut
+
+.sub 'push' :method
+ .param pmc value
+ push self, value
+.end
+
+
+.sub 'pop' :method
+ $P0 = self.'get_array'()
+ $P1 = pop $P0
+ .return ($P1)
+.end
+
+
+=item push_new(class, [child1, child2, ..., ] [attr1=>val1, attr2=>val2, ...])
+
+Creates a new PAST node of type C<class>, initializes it with the
+given children and attributes, and adds it to the end of the invocant's
+array of children. Returns the newly created PAST node.
+
+=cut
+
+.sub 'push_new' :method
+ .param string class
+ .param pmc children :slurpy
+ .param pmc adverbs :slurpy :named
+ $P0 = self.'new'(class, children :flat, adverbs :flat :named)
+ push self, $P0
+ .return ($P0)
+.end
+
+
+=item iterator( )
+
+Returns a newly initialized iterator for the invocant's list of
+children.
+
+=cut
+
+.sub 'iterator' :method
+ .local pmc iter
+ $P0 = self.'get_array'()
+ iter = new .Iterator, $P0
+ iter = 0
+ .return (iter)
+.end
+
+
+=item node([val])
+
+Sets the invocant's C<source> and C<pos> attributes to those
+of C<val>. If C<val> is another PAST node, then C<source> and C<pos>
+are simply copied from that node, otherwise C<val> is assumed to be
+a C<Match> object and obtains source/position information from that.
+
+=cut
+
+.sub 'node' :method
+ .param pmc node
+ $I0 = isa node, 'PAST::Node'
+ if $I0 goto clone_past
+ $I0 = isa node, 'Lua::PAST::Node'
+ if $I0 goto clone_past
+ clone_pge:
+ $S0 = node
+ $I0 = node.'from'()
+ self['source'] = $S0
+ self['pos'] = $I0
+ .return ()
+ clone_past:
+ $P0 = node['source']
+ $P1 = node['pos']
+ self['source'] = $P0
+ self['pos'] = $P1
+ .return ()
+.end
+
+
+=item attr(STR attrname, PMC value, INT has_value)
+
+Helper method for accessors. If C<has_value> is true then set
+the invocant's value of C<attrname> to C<value>. Returns the
+(resulting) value of C<attrname> in the invocant.
+
+=cut
+
+.sub 'attr' :method
+ .param string attrname
+ .param pmc value
+ .param int has_value
+ if has_value goto setattr
+ value = self[attrname]
+ unless null value goto getattr
+ value = new 'Undef'
+ getattr:
+ .return (value)
+ setattr:
+ self[attrname] = value
+ .return (value)
+.end
+
+
+=item name([value])
+
+Accessor method -- sets/returns the C<name> attribute of the invocant.
+
+=cut
+
+.sub 'name' :method
+ .param pmc value :optional
+ .param int has_value :opt_flag
+ .return self.'attr'('name', value, has_value)
+.end
+
+
+.namespace [ 'Lua::POST' ]
+
+.sub '__onload' :load :init
+ .local pmc base
+
+ base = subclass 'Lua::PAST::Node', 'Lua::POST::Node'
+
+ $P0 = subclass base, 'Lua::POST::Op'
+ $P0 = subclass base, 'Lua::POST::Ops'
+ $P0 = subclass base, 'Lua::POST::Label'
+ $P0 = subclass base, 'Lua::POST::Sub'
+ $P0 = subclass $P0, 'Lua::POST::Chunk'
+
+ $P0 = new 'Integer'
+ $P0 = 10
+ set_hll_global ['Lua::POST::Node'], '$!serno', $P0
+
+ .return ()
+.end
+
+
+=head1 POST Node types
+
+=head2 POST::Node
+
+C<POST::Node> is the base class for all POST nodes. It's derived from class
+C<PAST::Node> (see F<compilers/past-pm/PAST/Node.pir>).
+
+=over 4
+
+=item result([value])
+
+Get/set
+
+=cut
+
+.namespace [ 'Lua::POST::Node' ]
+
+.sub 'result' :method
+ .param pmc value :optional
+ .param int has_value :opt_flag
+
+ if has_value == 1 goto set_value
+ value = self['result']
+ unless null value goto end
+ value = self.'unique'('$P')
+ goto set_value_1
+ set_value:
+ $I0 = isa value, 'Lua::POST::Node'
+ if $I0 == 0 goto set_value_1
+ value = value.'result'()
+ set_value_1:
+ self['result'] = value
+ end:
+ .return (value)
+.end
+
+
+=item escape(STR name)
+
+Returns C<name> in a format that can be compiled by PIR.
+
+=cut
+
+.sub 'escape' :method
+ .param string str
+ str = escape str
+ str = concat '"', str
+ str = concat str, '"'
+ $I0 = index str, '\x'
+ if $I0 >= 0 goto unicode
+ $I0 = index str, '\u'
+ if $I0 >= 0 goto unicode
+ .return (str)
+ unicode:
+ str = concat 'unicode:', str
+ .return (str)
+.end
+
+
+=item unique([STR fmt])
+
+Generate a unique number that can be used as an identifier.
+If C<fmt> is provided, then it will be used as a prefix to the
+unique number.
+
+=cut
+
+.sub 'unique' :method
+ .param pmc fmt :slurpy
+ $S1 = join '', fmt
+ $P0 = get_global '$!serno'
+ $S0 = $P0
+ $S0 = concat $S1, $S0
+ inc $P0
+ .return ($S0)
+.end
+
+
+=item push_pirop(pirop [,arglist :slurpy] [,adverbs :slurpy :named])
+
+=cut
+
+.sub 'push_pirop' :method
+ .param pmc pirop
+ .param pmc arglist :slurpy
+ .param pmc adverbs :slurpy :named
+ if null adverbs goto no_adverbs
+ adverbs['pirop'] = pirop
+ $P0 = self.'push_new'('Lua::POST::Op', adverbs :flat :named)
+ goto end
+ no_adverbs:
+ $P0 = self.'push_new'('Lua::POST::Op', 'pirop'=>pirop)
+ end:
+ $P0.'arglist'(arglist :flat)
+ .return ($P0)
+.end
+
+
+=item cpir()
+
+=cut
+
+.sub 'cpir' :method
+ .local pmc code, iter
+ code = new 'CodeString'
+ iter = self.'iterator'()
+ iter_loop:
+ unless iter goto iter_end
+ .local pmc cpost
+ cpost = shift iter
+ $P0 = cpost.'pir'()
+ code .= $P0
+ goto iter_loop
+ iter_end:
+ .return (code)
+.end
+
+
+=back
+
+=head2 POST::Ops
+
+C<POST::Ops> is a container of C<POST::Node>.
+
+=over 4
+
+=item pir()
+
+=cut
+
+.namespace [ 'Lua::POST::Ops' ]
+
+.sub 'pir' :method
+ .return self.'cpir'()
+.end
+
+
+=back
+
+=head2 POST::Op
+
+C<POST::Op> nodes represents any PIR opcodes.
+
+=over 4
+
+=item pirop([opcode])
+
+Get/set
+
+call, callmethod, tailcall, inline
+
+=cut
+
+.namespace [ 'Lua::POST::Op' ]
+
+.sub 'pirop' :method
+ .param pmc value :optional
+ .param int has_value :opt_flag
+ .return self.'attr'('pirop', value, has_value)
+.end
+
+=item arglist(arglist)
+
+=cut
+
+.sub 'arglist' :method
+ .param pmc arglist :slurpy
+ .local int argc
+ argc = elements arglist
+ $I0 = 0
+ argc_loop:
+ if $I0 >= argc goto argc_end
+ $P0 = arglist[$I0]
+ $I1 = isa $P0, 'Lua::POST::Node'
+ if $I1 == 0 goto argc_next
+ $S0 = $P0.'result'()
+ arglist[$I0] = $S0
+ argc_next:
+ inc $I0
+ if $I0 < argc goto argc_loop
+ argc_end:
+ self['arglist'] = arglist
+ .return (arglist)
+.end
+
+
+=item pir()
+
+=cut
+
+.sub 'pir' :method
+ .local pmc code, arglist
+ code = self.'cpir'()
+ arglist = self['arglist']
+ .local string pirop
+ pirop = self.'pirop'()
+ if pirop == 'call' goto pir_call
+ if pirop == 'callmethod' goto pir_callmethod
+ if pirop == 'tailcall' goto pir_tailcall
+ if pirop == 'inline' goto pir_inline
+ code.'emit'(' %n %,', arglist :flat, 'n'=>pirop)
+ .return (code)
+
+ pir_call:
+ .local pmc result, name
+ result = self.'result'()
+ name = shift arglist
+ if result == '' goto call_without_ret
+ code.'emit'(' %r = %n(%,)', arglist :flat, 'r'=>result, 'n'=>name)
+ .return (code)
+ call_without_ret:
+ code.'emit'(' %n(%,)', arglist :flat, 'n'=>name)
+ .return (code)
+
+ pir_callmethod:
+ .local pmc result, name, invocant
+ result = self.'result'()
+ name = shift arglist
+ invocant = shift arglist
+ if result == '' goto callmethod_without_ret
+ code.'emit'(' %r = %i.%n(%,)', arglist :flat, 'r'=>result,
'i'=>invocant, 'n'=>name)
+ .return (code)
+ callmethod_without_ret:
+ code.'emit'(' %i.%n(%,)', arglist :flat, 'i'=>invocant, 'n'=>name)
+ .return (code)
+
+ pir_tailcall:
+ .local pmc name
+ name = shift arglist
+ code.'emit'(' .return %n(%,)', arglist :flat, 'n'=>name)
+ .return (code)
+
+ pir_inline:
+ .local pmc result, inline
+ result = self.'result'()
+ inline = shift arglist
+ code.'emit'(inline, arglist :flat, 'r'=>result, 't'=>result, 'u'=>result)
+ .return (code)
+.end
+
+
+=back
+
+=head2 POST::Label
+
+C<POST::Label> nodes represent PIR labels.
+
+=over 4
+
+=item result([value])
+
+Get/set
+
+=cut
+
+.namespace [ 'Lua::POST::Label' ]
+
+.sub 'result' :method
+ .param pmc value :optional
+ .param int has_value :opt_flag
+ if has_value goto set_value
+ value = self['value']
+ unless null value goto end
+ .local string name
+ name = self.'name'()
+ value = self.'unique'(name)
+ set_value:
+ self['value'] = value
+ end:
+ .return(value)
+.end
+
+
+=item pir()
+
+=cut
+
+.sub 'pir' :method
+ .local string code
+ .local string value
+ value = self.'result'()
+ code = ' '
+ code .= value
+ code .= ":\n"
+ .return (code)
+.end
+
+
+=back
+
+=head2 POST::Sub
+
+C<POST::Sub> nodes represent PIR subroutines.
+
+=over 4
+
+=item pir()
+
+=cut
+
+.namespace [ 'Lua::POST::Sub' ]
+
+.sub 'pir' :method
+ $S0 = self.'compiler'()
+ unless $S0 goto post_pir
+ .return self.'hll_pir'()
+ post_pir:
+ .local string name
+ name = self.'name'()
+ name = self.'escape'(name)
+ .local pmc outerpost
+ .local string outer
+ outer = ''
+ outerpost = self.'outer'()
+ if null outerpost goto have_outer
+ unless outerpost goto have_outer
+ outer = outerpost.'name'()
+ outer = outerpost.'escape'(outer)
+ outer = concat ':outer(', outer
+ outer = concat outer, ')'
+ have_outer:
+ .local string pragma
+ pragma = self.'pragma'()
+ .local pmc code
+ code = new 'CodeString'
+ .local string namespace
+ namespace = self.'namespace'()
+ unless namespace goto have_namespace
+ code.'emit'("\n.namespace [ '%0' ]", namespace)
+ have_namespace:
+ code.'emit'("\n.sub %0 %1 %2", name, outer, pragma)
+ $P0 = self.'paramcode'()
+ code .= $P0
+ .local pmc iter, cpost
+ iter = self.'iterator'()
+ iter_loop:
+ unless iter goto iter_end
+ cpost = shift iter
+ $P1 = cpost.'pir'()
+ code .= $P1
+ goto iter_loop
+ iter_end:
+ .local string value
+ value = self.'result'()
+ if value == '' goto no_return
+ code.'emit'(" .return (%0)\n", value)
+ no_return:
+ code.'emit'(".end\n")
+ $P0 = get_hll_global ['Lua::POST'], '$!subpir'
+ code .= $P0
+ set_hll_global ['Lua::POST'], '$!subpir', code
+
+ code = new 'CodeString'
+ $S0 = self.'blocktype'()
+ if $S0 == 'declaration' goto skip_declaration
+ code.'emit'(" %0 = find_name %1", value, name)
+ if $S0 == 'END' goto add_end_block
+ skip_declaration:
+ .return (code)
+ add_end_block:
+ $S1 = code.'unique'('$P')
+ code.'emit'(" %0 = find_global '_perl6', '%BLOCKS'", $S1)
+ code.'emit'(" %0 = %0['END']", $S1)
+ code.'emit'(" push %0, %1", $S1, value)
+ .return (code)
+.end
+
+
+.sub 'hll_pir' :method
+ .local string compname, name
+ compname = self.'compiler'()
+ name = self.'name'()
+ .local pmc adverbs
+ adverbs = new .Hash
+ adverbs['target'] = 'pir'
+ adverbs['name'] = name
+ adverbs['grammar'] = ''
+ .local pmc outerpost
+ outerpost = self.'outer'()
+ unless outerpost goto have_outer
+ $S0 = outerpost.'name'()
+ adverbs['outer'] = $S0
+ have_outer:
+ .local pmc sourcecode, compiler, pircode
+ sourcecode = self[0]
+ compiler = compreg compname
+ $I0 = isa compiler, 'Sub'
+ if $I0 goto compile_sub
+ pircode = compiler.'compile'(sourcecode, adverbs :flat :named)
+ goto have_pircode
+ compile_sub:
+ pircode = compiler(sourcecode, adverbs :flat :named)
+ have_pircode:
+ $P0 = get_hll_global ['Lua::POST'], '$!subpir'
+ pircode .= $P0
+ set_hll_global ['Lua::POST'], '$!subpir', pircode
+ .local string result
+ result = self.'result'()
+ name = self.'escape'(name)
+ .local pmc code
+ code = new 'CodeString'
+ code.'emit'(" %0 = find_name %1", result, name)
+ .return (code)
+.end
+
+
+=item outer([outer])
+
+Get/set
+
+=cut
+
+.sub 'outer' :method
+ .param pmc value :optional
+ .param int has_value :opt_flag
+ .return self.'attr'('outer', value, has_value)
+.end
+
+
+=item pragma([pragma])
+
+Get/set
+
+=cut
+
+.sub 'pragma' :method
+ .param pmc value :optional
+ .param int has_value :opt_flag
+ .return self.'attr'('pragma', value, has_value)
+.end
+
+
+=item blocktype([type])
+
+Get/set
+
+=cut
+
+.sub 'blocktype' :method
+ .param pmc value :optional
+ .param int has_value :opt_flag
+ .return self.'attr'('blocktype', value, has_value)
+.end
+
+
+=item namespace([name])
+
+Get/set the namespace for this sub. If called to retrieve the namespace,
+use any outer namespace if it exists.
+
+=cut
+
+.sub 'namespace' :method
+ .param pmc value :optional
+ .param int has_value :opt_flag
+ .local string namespace
+ namespace = self.'attr'('namespace', value, has_value)
+ if namespace goto end
+ if has_value goto end
+ .local pmc outer
+ outer = self.'outer'()
+ if null outer goto end
+ unless outer goto end
+ namespace = outer.'namespace'()
+ end:
+ .return (namespace)
+.end
+
+=item paramcode([paramcode])
+
+Get/set
+
+=cut
+
+.sub 'paramcode' :method
+ .param pmc value :optional
+ .param int has_value :opt_flag
+ .return self.'attr'('paramcode', value, has_value)
+.end
+
+
+=item compiler([name])
+
+Get/set
+
+=cut
+
+.sub 'compiler' :method
+ .param pmc value :optional
+ .param int has_value :opt_flag
+ .return self.'attr'('compiler', value, has_value)
+.end
+
+
+=item push_param(STR regtype, STR pname, STR flags, INT has_flags)
+
+=cut
+
+.sub 'push_param' :method
+ .param string regtype
+ .param string pname
+ .param string flags :optional
+ .param int has_flags :opt_flag
+
+ .local pmc paramcode
+ paramcode = self.'paramcode'()
+ if paramcode goto add_param
+ paramcode = new 'CodeString'
+ self.'paramcode'(paramcode)
+ add_param:
+ if has_flags goto have_flags
+ flags = ''
+ have_flags:
+ paramcode.'emit'(' .param %0 %1 %2', regtype, pname, flags)
+ .return ()
+.end
+
+
+.sub 'ops_const' :method
+ .param pmc value :optional
+ .param int has_value :opt_flag
+ .return self.'attr'('ops_const', value, has_value)
+.end
+
+.sub 'ops_subr' :method
+ .param pmc value :optional
+ .param int has_value :opt_flag
+ .return self.'attr'('ops_subr', value, has_value)
+.end
+
+.sub 'storage_const' :method
+ .param pmc value :optional
+ .param int has_value :opt_flag
+ .return self.'attr'('storage_const', value, has_value)
+.end
+
+.sub 'storage_lex' :method
+ .param pmc value :optional
+ .param int has_value :opt_flag
+ .return self.'attr'('storage_lex', value, has_value)
+.end
+
+
+.namespace [ 'Lua::POST::Chunk' ]
+
+.sub 'prologue' :method
+ .param pmc value :optional
+ .param int has_value :opt_flag
+ .return self.'attr'('prologue', value, has_value)
+.end
+
+.sub 'pir' :method
+ self.'cpir'()
+ $S0 = self.'prologue'()
+ if $S0 == '' goto L1
+ .local pmc code
+ new code, 'CodeString'
+ code.'emit'($S0)
+ $P0 = get_hll_global ['Lua::POST'], '$!subpir'
+ code .= $P0
+ set_hll_global ['Lua::POST'], '$!subpir', code
+ L1:
+.end
+
+
+=head1 NAME
+
+POST::Compiler - Compiler for POST trees
+
+=head1 DESCRIPTION
+
+POST::Compiler defines a compiler that converts a POST tree into
+either PIR or executable bytecode.
+
+=head1 METHODS
+
+=cut
+
+.namespace [ 'Lua::POST::Compiler' ]
+
+.sub '__onload' :load :init
+ load_bytecode 'Parrot/HLLCompiler.pbc'
+
+ $P99 = subclass 'HLLCompiler', 'Lua::POST::Compiler'
+ $P0 = new 'Lua::POST::Compiler'
+ $P0.'language'('POST')
+ .return ()
+.end
+
+
+.sub 'compile' :method
+ .param pmc post
+ .param pmc adverbs :slurpy :named
+
+ $I0 = isa post, 'Lua::POST::Sub'
+ if $I0 goto with_sub
+ $S0 = typeof post
+ say $S0
+ post = post.'new'('Lua::POST::Sub', post, 'name'=>'anon')
+ with_sub:
+ .local pmc code
+ code = new 'CodeString'
+ set_hll_global ['Lua::POST'], '$!subpir', code
+ post.'pir'()
+
+ code = get_hll_global ['Lua::POST'], '$!subpir'
+ .return (code)
+.end
+
+
+=back
+
+=head1 HISTORY
+
+Mostly taken from F<compilers/past-pm/PAST/Node.pir>,
+F<compilers/past-pm/POST/Node.pir>, and
+F<compilers/past-pm/POST/Compiler.pir>.
+
+=cut
+
+
+# Local Variables:
+# mode: pir
+# fill-column: 100
+# End:
+# vim: expandtab shiftwidth=4 ft=pir:
Modified: trunk/languages/lua/src/POSTGrammar.tg
==============================================================================
--- trunk/languages/lua/src/POSTGrammar.tg (original)
+++ trunk/languages/lua/src/POSTGrammar.tg Thu Mar 27 03:44:08 2008
@@ -1,4 +1,4 @@
-# Copyright (C) 2007, The Perl Foundation.
+# Copyright (C) 2007-2008, The Perl Foundation.
# $Id$
=head1 NAME
@@ -28,17 +28,17 @@
unless $S0 == '' goto L1
$S0 = 'anon'
L1:
- name = node.'unique'($S0, '_')
.local pmc post
- new post, 'POST::Sub'
+ new post, 'Lua::POST::Sub'
+ name = post.'unique'($S0, '_')
post.'init'('node'=>node, 'name'=>name, 'outer'=>outerpost,
'pragma'=>':anon :lex', 'blocktype'=>'declaration', 'result'=>'')
new $P0, 'Hash'
post.'storage_lex'($P0)
new $P0, 'Hash'
post.'storage_const'($P0)
- $P0 = post.'push_new'('POST::Ops')
+ $P0 = post.'push_new'('Lua::POST::Ops')
post.'ops_const'($P0)
- $P1 = post.'push_new'('POST::Ops')
+ $P1 = post.'push_new'('Lua::POST::Ops')
post.'ops_subr'($P1)
set_hll_global ['Lua::POST'], '$?SUB', post
.local pmc iter, cpost
@@ -53,7 +53,7 @@
set_hll_global ['Lua::POST'], '$?SUB', outerpost
set_hll_global ['Lua::POST'], '@endlabels', endlabels
.local string esc_name
- esc_name = node.'escape'(name)
+ esc_name = post.'escape'(name)
if null outerpost goto L4
.local pmc ops_subr
ops_subr = outerpost.'ops_subr'()
@@ -64,9 +64,9 @@
outerpost.'ops_subr'($P0)
L5:
.local pmc ops
- ops = post.'new'('POST::Ops', 'node'=>node)
+ ops = post.'new'('Lua::POST::Ops', 'node'=>node)
ops.'push'(post)
- $S0 = node.'unique'('fct_')
+ $S0 = post.'unique'('fct_')
ops.'push_pirop'('inline', ' .const .Sub %0 = %1', $S0, esc_name)
$P0 = ops.'push_pirop'('newclosure')
$P0.'arglist'($P0, $S0)
@@ -76,7 +76,7 @@
.return (ops)
L4:
.local pmc start
- start = post.'new'('POST::Sub', 'name'=>'&start', 'pragma'=>':anon :main',
'result'=>'')
+ start = post.'new'('Lua::POST::Sub', 'name'=>'&start', 'pragma'=>':anon
:main', 'result'=>'')
start.'push_pirop'('inline', ' .param pmc args :optional')
start.'push_pirop'('inline', '# print "start\n"')
start.'push_pirop'('inline', ' load_bytecode "languages/lua/lua.pbc"')
@@ -102,7 +102,7 @@
transform post (PAST::Stmts) :language('PIR') {
.local pmc ops
- new ops, 'POST::Ops'
+ new ops, 'Lua::POST::Ops'
ops.'init'('node'=>node)
.local pmc iter
iter = node.'iterator'()
@@ -166,7 +166,7 @@
post.'result'($P0)
.return (post)
L1:
- new post, 'POST::Op'
+ new post, 'Lua::POST::Op'
post.'init'('node'=>node, 'pirop'=>$S0)
.local pmc arglist, iter
new arglist, 'ResizableStringArray'
@@ -188,7 +188,7 @@
transform cmp (PAST::Op) :language('PIR') {
.local pmc ops
- new ops, 'POST::Ops'
+ new ops, 'Lua::POST::Ops'
ops.'init'('node'=>node)
.local pmc expr1
$P0 = node[0]
@@ -200,7 +200,7 @@
ops.'push'(expr2)
.local string pirop
pirop = node.'pirop'()
- $S0 = node.'unique'('$I')
+ $S0 = ops.'unique'('$I')
ops.'push_pirop'(pirop, $S0, expr1, expr2)
ops.'result'($S0)
.return (ops)
@@ -209,7 +209,7 @@
transform call (PAST::Op) :language('PIR') {
.local pmc post
- new post, 'POST::Op'
+ new post, 'Lua::POST::Op'
post.'init'('node'=>node, 'pirop'=>'call', 'result'=>'')
.local pmc arglist, iter, cpost
new arglist, 'ResizableStringArray'
@@ -224,7 +224,7 @@
$S0 = cpost.'result'()
if first goto L3
if iter goto L3
- $I0 = isa cpost, 'POST::Op'
+ $I0 = isa cpost, 'Lua::POST::Op'
unless $I0 goto L3
$S1 = cpost.'pirop'()
unless $S1 == 'call' goto L3
@@ -246,14 +246,14 @@
transform len (PAST::Op) :language('PIR') {
.local pmc ops
- new ops, 'POST::Ops'
+ new ops, 'Lua::POST::Ops'
ops.'init'('node'=>node)
.local pmc expr
$P0 = node[0]
expr = tree.'get'('post', $P0)
ops.'push'(expr)
$P0 = ops.'push_pirop'('callmethod', 'node'=>node)
- $S0 = node.'escape'('len')
+ $S0 = ops.'escape'('len')
$P0.'arglist'($S0, expr)
ops.'result'($P0)
.return (ops)
@@ -262,7 +262,7 @@
transform and (PAST::Op) :language('PIR') {
.local pmc ops
- new ops, 'POST::Ops'
+ new ops, 'Lua::POST::Ops'
ops.'init'('node'=>node)
.local string type
type = node.'pasttype'()
@@ -271,11 +271,11 @@
expr1 = tree.'get'('post', $P0)
ops.'push'(expr1)
.local pmc label, endlabel
- $S0 = node.'unique'(type, '_')
- label = ops.'new'('POST::Label', 'result'=>$S0)
+ $S0 = ops.'unique'(type, '_')
+ label = ops.'new'('Lua::POST::Label', 'result'=>$S0)
$S0 = $S0 . '_end'
- endlabel = ops.'new'('POST::Label', 'result'=>$S0)
- $S0 = node.'unique'('$P')
+ endlabel = ops.'new'('Lua::POST::Label', 'result'=>$S0)
+ $S0 = ops.'unique'('$P')
unless type == 'and' goto L1
ops.'push_pirop'('if', expr1, label)
goto L2
@@ -303,7 +303,7 @@
transform vararg (PAST::Op) :language('PIR') {
.local pmc post
- new post, 'POST::Op'
+ new post, 'Lua::POST::Op'
post.'init'('node'=>node, 'pirop'=>'call')
post.'arglist'('mkarg', 'vararg')
$P0 = post.'push_pirop'('new')
@@ -315,13 +315,13 @@
transform if (PAST::Op) :language('PIR') {
.local pmc ops
- new ops, 'POST::Ops'
+ new ops, 'Lua::POST::Ops'
ops.'init'('node'=>node)
.local pmc thenlabel, endlabel
- $S0 = node.'unique'('if_')
- thenlabel = ops.'new'('POST::Label', 'result'=>$S0)
+ $S0 = ops.'unique'('if_')
+ thenlabel = ops.'new'('Lua::POST::Label', 'result'=>$S0)
$S0 = $S0 . '_end'
- endlabel = ops.'new'('POST::Label', 'result'=>$S0)
+ endlabel = ops.'new'('Lua::POST::Label', 'result'=>$S0)
.local pmc expr
$P0 = node[0]
expr = tree.'get'('cond', $P0)
@@ -352,13 +352,13 @@
.local pmc endlabels
endlabels = get_hll_global ['Lua::POST'], '@endlabels'
.local pmc ops
- new ops, 'POST::Ops'
+ new ops, 'Lua::POST::Ops'
ops.'init'('node'=>node)
.local pmc looplabel, endlabel
- $S0 = node.'unique'('while_')
- looplabel = ops.'new'('POST::Label', 'result'=>$S0)
+ $S0 = ops.'unique'('while_')
+ looplabel = ops.'new'('Lua::POST::Label', 'result'=>$S0)
$S0 = $S0 . '_end'
- endlabel = ops.'new'('POST::Label', 'result'=>$S0)
+ endlabel = ops.'new'('Lua::POST::Label', 'result'=>$S0)
unshift endlabels, endlabel
ops.'push'(looplabel)
.local pmc expr
@@ -381,13 +381,13 @@
.local pmc endlabels
endlabels = get_hll_global ['Lua::POST'], '@endlabels'
.local pmc ops
- new ops, 'POST::Ops'
+ new ops, 'Lua::POST::Ops'
ops.'init'('node'=>node)
.local pmc looplabel, endlabel
- $S0 = node.'unique'('repeat_')
- looplabel = ops.'new'('POST::Label', 'result'=>$S0)
+ $S0 = ops.'unique'('repeat_')
+ looplabel = ops.'new'('Lua::POST::Label', 'result'=>$S0)
$S0 = $S0 . '_end'
- endlabel = ops.'new'('POST::Label', 'result'=>$S0)
+ endlabel = ops.'new'('Lua::POST::Label', 'result'=>$S0)
unshift endlabels, endlabel
ops.'push'(looplabel)
.local pmc blk
@@ -410,7 +410,7 @@
.local pmc endlabels
endlabels = get_hll_global ['Lua::POST'], '@endlabels'
.local pmc ops
- new ops, 'POST::Ops'
+ new ops, 'Lua::POST::Ops'
ops.'init'('node'=>node)
.local pmc e_var, e_limit, e_step
$P0 = node[1]
@@ -430,23 +430,23 @@
var = $P0.'result'()
ops.'push'($P0)
.local string limit, step
- limit = node.'unique'('$P')
- step = node.'unique'('$P')
+ limit = ops.'unique'('$P')
+ step = ops.'unique'('$P')
ops.'push_pirop'('inline', ' (%0, %1, %2) = checkforloop(%3, %4, %5)',
var, limit, step, e_var, e_limit, e_step)
.local string incr
- $S0 = node.'unique'('$N')
+ $S0 = ops.'unique'('$N')
ops.'push_pirop'('set', $S0, step)
- incr = node.'unique'('$I')
+ incr = ops.'unique'('$I')
ops.'push_pirop'('isgt', incr, $S0, '0.0')
.local pmc looplabel, endlabel, orlabel, blklabel
- $S0 = node.'unique'('fornum_')
- looplabel = ops.'new'('POST::Label', 'result'=>$S0)
+ $S0 = ops.'unique'('fornum_')
+ looplabel = ops.'new'('Lua::POST::Label', 'result'=>$S0)
$S1 = $S0 . '_or'
- orlabel = ops.'new'('POST::Label', 'result'=>$S1)
+ orlabel = ops.'new'('Lua::POST::Label', 'result'=>$S1)
$S1 = $S0 . '_blk'
- blklabel = ops.'new'('POST::Label', 'result'=>$S1)
+ blklabel = ops.'new'('Lua::POST::Label', 'result'=>$S1)
$S1 = $S0 . '_end'
- endlabel = ops.'new'('POST::Label', 'result'=>$S1)
+ endlabel = ops.'new'('Lua::POST::Label', 'result'=>$S1)
unshift endlabels, endlabel
ops.'push'(looplabel)
ops.'push_pirop'('unless', incr, orlabel)
@@ -471,7 +471,7 @@
.local pmc endlabels
endlabels = get_hll_global ['Lua::POST'], '@endlabels'
.local pmc ops
- new ops, 'POST::Ops'
+ new ops, 'Lua::POST::Ops'
ops.'init'('node'=>node)
.local pmc explist, rpost
explist = node[1]
@@ -483,7 +483,7 @@
ops.'push'(rpost)
func = rpost.'result'()
if iter goto L1
- $I0 = isa rpost, 'POST::Op'
+ $I0 = isa rpost, 'Lua::POST::Op'
unless $I0 goto L1
$S0 = rpost.'pirop'()
unless $S0 == 'call' goto L1
@@ -507,7 +507,7 @@
ops.'push'(rpost)
state = rpost.'result'()
if iter goto L2
- $I0 = isa rpost, 'POST::Op'
+ $I0 = isa rpost, 'Lua::POST::Op'
unless $I0 goto L2
$S0 = rpost.'pirop'()
unless $S0 == 'call' goto L2
@@ -557,10 +557,10 @@
goto L7
L8:
.local pmc looplabel, endlabel
- $S0 = node.'unique'('forlist_')
- looplabel = ops.'new'('POST::Label', 'result'=>$S0)
+ $S0 = ops.'unique'('forlist_')
+ looplabel = ops.'new'('Lua::POST::Label', 'result'=>$S0)
$S0 = $S0 . '_end'
- endlabel = ops.'new'('POST::Label', 'result'=>$S0)
+ endlabel = ops.'new'('Lua::POST::Label', 'result'=>$S0)
unshift endlabels, endlabel
ops.'push'(looplabel)
new iter, 'Iterator', tmp
@@ -582,7 +582,7 @@
$P0 = ops.'push_pirop'('assign')
$S0 = tmp[0]
$P0.'arglist'(var, $S0)
- $S0 = node.'unique'('$I')
+ $S0 = ops.'unique'('$I')
ops.'push_pirop'('isa', $S0, var, '"LuaNil"')
ops.'push_pirop'('if', $S0, endlabel)
.local pmc blk
@@ -598,7 +598,7 @@
transform return (PAST::Op) :language('PIR') {
.local pmc ops
- new ops, 'POST::Ops'
+ new ops, 'Lua::POST::Ops'
ops.'init'('node'=>node)
.local string result
result = '('
@@ -611,7 +611,7 @@
ops.'push'(cpost)
$S0 = cpost.'result'()
if iter goto L3
- $I0 = isa cpost, 'POST::Op'
+ $I0 = isa cpost, 'Lua::POST::Op'
unless $I0 goto L3
$S1 = cpost.'pirop'()
unless $S1 == 'call' goto L3
@@ -641,7 +641,7 @@
.local pmc endlabels
endlabels = get_hll_global ['Lua::POST'], '@endlabels'
.local pmc post
- new post, 'POST::Op'
+ new post, 'Lua::POST::Op'
post.'init'('node'=>node, 'pirop'=>'goto')
$P0 = endlabels[0]
post.'arglist'($P0)
@@ -658,14 +658,14 @@
lpost = tree.'get'('post', $P0)
lpost.'arglist'(lpost, rpost)
.local pmc ops
- ops = lpost.'new'('POST::Ops', rpost, lpost, 'node'=>node)
+ ops = lpost.'new'('Lua::POST::Ops', rpost, lpost, 'node'=>node)
.return (ops)
}
transform assignlist (PAST::Op) :language('PIR') {
.local pmc lpost, rpost, ops
- new ops, 'POST::Ops'
+ new ops, 'Lua::POST::Ops'
ops.'init'('node'=>node)
.local pmc namelist, explist
namelist = node[0]
@@ -681,7 +681,7 @@
$S1 = rpost.'result'()
push tmp, $S1
if iter goto L1
- $I0 = isa rpost, 'POST::Op'
+ $I0 = isa rpost, 'Lua::POST::Op'
unless $I0 goto L1
$S0 = rpost.'pirop'()
unless $S0 == 'call' goto L1
@@ -705,7 +705,7 @@
rpost.'result'($S0)
L2:
.local pmc ass
- new ass, 'POST::Ops'
+ new ass, 'Lua::POST::Ops'
ass.'init'('node'=>node)
new iter, 'Iterator', namelist
L5:
@@ -733,7 +733,7 @@
transform parenthese (PAST::Op) :language('PIR') {
.local pmc ops
- new ops, 'POST::Ops'
+ new ops, 'Lua::POST::Ops'
ops.'init'('node'=>node)
.local pmc expr
$P0 = node[0]
@@ -750,29 +750,29 @@
transform post (PAST::Val) :language('PIR') {
- .local string vtype
- vtype = node.'vtype'()
- $I0 = index vtype, 'Lua'
+ .local string type
+ type = node.'name'()
+ $I0 = index type, 'Lua'
if $I0 < 0 goto L1
.local pmc ops
- new ops, 'POST::Ops'
+ new ops, 'Lua::POST::Ops'
ops.'init'('node'=>node)
.local pmc val
val = ops.'push_pirop'('new')
- $S0 = node.'escape'(vtype)
+ $S0 = ops.'escape'(type)
val.'arglist'(val, $S0)
- .local string name
- name = node.'name'()
- if name == '' goto L2
- unless vtype == 'LuaString' goto L3
- name = node.'escape'(name)
+ .local string value
+ value = node.'value'()
+ if value == '' goto L2
+ unless type == 'LuaString' goto L3
+ value = ops.'escape'(value)
L3:
- ops.'push_pirop'('set', val, name, 'result'=>val)
+ ops.'push_pirop'('set', val, value, 'result'=>val)
L2:
ops.'result'(val)
.return (ops)
L1:
- .return tree.'get'(vtype, node)
+ .return tree.'get'(type, node)
}
@@ -782,18 +782,18 @@
.local pmc storage_const
storage_const = subpost.'storage_const'()
.local string name
- name = node.'name'()
+ name = node.'value'()
$I0 = exists storage_const[name]
if $I0 goto L1
.local pmc ops_const
ops_const = subpost.'ops_const'()
$S0 = 'k_' . name
- $S1 = node.'escape'(name)
+ $S1 = ops_const.'escape'(name)
$P0 = ops_const.'push_pirop'('inline', ' .const .LuaString %0 = %1',
$S0, $S1)
storage_const[name] = $S0
L1:
.local pmc ops
- new ops, 'POST::Ops'
+ new ops, 'Lua::POST::Ops'
ops.'init'('node'=>node)
$S0 = storage_const[name]
ops.'result'($S0)
@@ -803,7 +803,7 @@
transform constructor (PAST::Val) :language('PIR') {
.local pmc ops
- new ops, 'POST::Ops'
+ new ops, 'Lua::POST::Ops'
ops.'init'('node'=>node)
.local pmc val
val = ops.'push_pirop'('new')
@@ -819,7 +819,7 @@
$P0 = shift iter
$I0 = does $P0, 'array'
if $I0 goto L3
- kpost = ops.'new'('POST::Ops', 'node'=>node)
+ kpost = ops.'new'('Lua::POST::Ops', 'node'=>node)
$P1 = kpost.'push_pirop'('new')
$P1.'arglist'($P1, '"LuaNumber"')
$S0 = i
@@ -828,7 +828,7 @@
kpost.'result'($P1)
vpost = tree.'get'('post', $P0)
if iter goto L4
- $I0 = isa vpost, 'POST::Op'
+ $I0 = isa vpost, 'Lua::POST::Op'
unless $I0 goto L4
$S0 = vpost.'pirop'()
unless $S0 == 'call' goto L4
@@ -877,11 +877,11 @@
.local pmc subpost
subpost = get_hll_global ['Lua::POST'], '$?SUB'
.local pmc ops
- new ops, 'POST::Ops'
+ new ops, 'Lua::POST::Ops'
ops.'init'('node'=>node)
.local string name
name = node.'name'()
- $I0 = node.'isslurpy'()
+ $I0 = node.'slurpy'()
unless $I0 goto L1
subpost.'push_param'('pmc', name, ':slurpy')
.return (ops)
@@ -891,10 +891,10 @@
.local string pname
pname = 'param_' . name
subpost.'push_param'('pmc', pname, ':optional')
- $S0 = node.'escape'(name)
+ $S0 = ops.'escape'(name)
ops.'push_pirop'('.lex', $S0, pname)
.local pmc vivilabel
- vivilabel = ops.'new'('POST::Label', 'name'=>'vivify_')
+ vivilabel = ops.'new'('Lua::POST::Label', 'name'=>'vivify_')
ops.'push_pirop'('unless_null', pname, vivilabel)
ops.'push_pirop'('new', pname, '"LuaNil"')
ops.'push'(vivilabel)
@@ -910,12 +910,12 @@
.local pmc storage_lex
storage_lex = subpost.'storage_lex'()
.local pmc ops
- new ops, 'POST::Ops'
+ new ops, 'Lua::POST::Ops'
ops.'init'('node'=>node)
.local string name, lname
name = node.'name'()
- lname = node.'escape'(name)
- $I0 = node.'islvalue'()
+ lname = ops.'escape'(name)
+ $I0 = node.'lvalue'()
if $I0 goto L1
$I0 = exists storage_lex[name]
if $I0 goto L2
@@ -928,7 +928,7 @@
ops.'result'($S0)
.return (ops)
L1:
- $I0 = node.'ismy'()
+ $I0 = node.'isdecl'()
unless $I0 goto L3
$I0 = exists storage_lex[name]
if $I0 goto L3
@@ -940,7 +940,7 @@
storage_lex[name] = pname
L3:
.local pmc post
- new post, 'POST::Op'
+ new post, 'Lua::POST::Op'
post.'init'('node'=>node, 'pirop'=>'store_lex')
post.'push'(ops)
post.'result'(lname)
@@ -950,7 +950,7 @@
transform package (PAST::Var) :language('PIR') {
.local pmc ops
- new ops, 'POST::Ops'
+ new ops, 'Lua::POST::Ops'
ops.'init'('node'=>node)
.local pmc basepost, keypost
$S0 = node.'scope'()
@@ -987,11 +987,11 @@
.local pmc ops_const
ops_const = subpost.'ops_const'()
$S0 = 'k_' . name
- $S1 = node.'escape'(name)
+ $S1 = ops_const.'escape'(name)
$P0 = ops_const.'push_pirop'('inline', ' .const .LuaString %0 = %1',
$S0, $S1)
storage_const[name] = $S0
L5:
- new keypost, 'POST::Ops'
+ new keypost, 'Lua::POST::Ops'
keypost.'init'('node'=>node)
$S0 = storage_const[name]
keypost.'result'($S0)
@@ -1003,7 +1003,7 @@
key .= $S0
key .= ']'
ops.'result'(key)
- $I0 = node.'islvalue'()
+ $I0 = node.'lvalue'()
if $I0 goto L6
$P0 = ops.'push_pirop'('set')
$P0.'arglist'($P0, key)
@@ -1011,7 +1011,7 @@
.return (ops)
L6:
.local pmc post
- new post, 'POST::Op'
+ new post, 'Lua::POST::Op'
post.'init'('node'=>node, 'pirop'=>'set')
post.'push'(ops)
post.'result'(key)
Modified: trunk/languages/lua/src/lua51.pir
==============================================================================
--- trunk/languages/lua/src/lua51.pir (original)
+++ trunk/languages/lua/src/lua51.pir Thu Mar 27 03:44:08 2008
@@ -29,11 +29,8 @@
.namespace [ 'Lua' ]
.sub '__onload' :anon :load :init
- load_bytecode 'PGE.pbc'
- load_bytecode 'PGE/Util.pbc'
+ load_bytecode 'PCT.pbc'
load_bytecode 'PGE/Text.pbc'
- load_bytecode 'PAST-pm.pbc'
- load_bytecode 'PCT/HLLCompiler.pbc'
$P0 = subclass 'PCT::HLLCompiler', 'Lua::Compiler'
addattribute $P0, '$ostgrammar'
@@ -739,68 +736,6 @@
.end
-.namespace [ 'Lua::POST::Chunk' ]
-
-.sub '__onload' :anon :load :init
- $P0 = subclass 'POST::Sub', 'Lua::POST::Chunk'
-.end
-
-.sub 'prologue' :method
- .param pmc value :optional
- .param int has_value :opt_flag
- .return self.'attr'('prologue', value, has_value)
-.end
-
-.sub 'pir' :method
- self.'cpir'()
- $S0 = self.'prologue'()
- if $S0 == '' goto L1
- .local pmc code
- new code, 'CodeString'
- code.'emit'($S0)
- $P0 = get_hll_global ['POST'], '$!subpir'
- code .= $P0
- set_hll_global ['POST'], '$!subpir', code
- L1:
-.end
-
-
-.namespace [ 'POST::Node' ]
-
-.sub 'pop' :method
- $P0 = self.'get_array'()
- $P1 = pop $P0
- .return ($P1)
-.end
-
-
-.namespace [ 'POST::Sub' ]
-
-.sub 'ops_const' :method
- .param pmc value :optional
- .param int has_value :opt_flag
- .return self.'attr'('ops_const', value, has_value)
-.end
-
-.sub 'ops_subr' :method
- .param pmc value :optional
- .param int has_value :opt_flag
- .return self.'attr'('ops_subr', value, has_value)
-.end
-
-.sub 'storage_const' :method
- .param pmc value :optional
- .param int has_value :opt_flag
- .return self.'attr'('storage_const', value, has_value)
-.end
-
-.sub 'storage_lex' :method
- .param pmc value :optional
- .param int has_value :opt_flag
- .return self.'attr'('storage_lex', value, has_value)
-.end
-
-
.namespace [ 'Lua::Symbtab' ]
.sub '__onload' :anon :load :init
@@ -854,6 +789,7 @@
.include 'languages/lua/src/lua51_gen.pir'
.include 'languages/lua/src/PASTGrammar_gen.pir'
.include 'languages/lua/src/POSTGrammar_gen.pir'
+.include 'languages/lua/src/POST.pir'
=back