Author: fperrad
Date: Mon Jun 4 00:55:03 2007
New Revision: 18802
Modified:
trunk/languages/lua/src/PASTGrammar.tg
trunk/languages/lua/src/POSTGrammar.tg
trunk/languages/lua/src/lua51.pir
Log:
[Lua]
- PAST : fornum & forlist
- POST : repeat
- first Symbol Table
Modified: trunk/languages/lua/src/PASTGrammar.tg
==============================================================================
--- trunk/languages/lua/src/PASTGrammar.tg (original)
+++ trunk/languages/lua/src/PASTGrammar.tg Mon Jun 4 00:55:03 2007
@@ -16,6 +16,8 @@
transform past (ROOT) :language('PIR') {
.local pmc past
+ $P0 = new 'Lua::Symbtab'
+ set_hll_global ['Lua::PAST'], '$symbtab', $P0
$P0 = node['block']
past = tree.'get'('past', $P0, 'Lua::Grammar::block')
.return past.'new'('PAST::Block', past, 'node'=>node, 'name'=>'_main',
'pragma'=>':anon :lex')
@@ -30,19 +32,19 @@
if null $P0 goto L1
.local pmc iter
iter = new .Iterator, $P0
-L2:
+ L2:
unless iter goto L1
$P0 = shift iter
$P1 = tree.'get'('past', $P0, 'Lua::Grammar::statement')
past.'push'($P1)
goto L2
-L1:
+ L1:
$P0 = node['last_statement']
if null $P0 goto L3
$P0 = shift $P0
$P1 = tree.'get'('past', $P0, 'Lua::Grammar::statement')
past.'push'($P1)
-L3:
+ L3:
.return (past)
}
@@ -67,20 +69,20 @@
if null $P0 goto L1
.local pmc iter
iter = new .Iterator, $P0
-L2:
+ L2:
unless iter goto L1
$P0 = shift iter
$P1 = tree.'get'('past', $P0, 'Lua::Grammar::elseif_block')
cpast.'push'($P1)
cpast = $P1
goto L2
-L1:
+ L1:
$P0 = node['else_block']
if null $P0 goto L3
$P0 = shift $P0
$P1 = tree.'get'('past', $P0, 'Lua::Grammar::else_block')
cpast.'push'($P1)
-L3:
+ L3:
.return (past)
}
@@ -124,20 +126,65 @@
transform past (Lua::Grammar::for_stat) :language('PIR') {
+ .local pmc past
$S0 = node.'find_key'()
$P0 = node[$S0]
$S1 = concat 'Lua::Grammar::', $S0
- .return tree.'get'('past', $P0, $S1)
+ past = tree.'get'('past', $P0, $S1)
+ $P0 = node['for_body']
+ $P0 = $P0['block']
+ $P1 = tree.'get'('past', $P0, 'Lua::Grammar::block')
+ past.'push'($P1)
+ .return (past)
}
transform past (Lua::Grammar::fornum) :language('PIR') {
- internal_error("not implemented (fornum)")
+ .local pmc name, explist
+ .local pmc symbtab
+ symbtab = get_hll_global ['Lua::PAST'], '$symbtab'
+ $P0 = node['name']
+ $S0 = $P0.'result_object'()
+ symbtab.'insert'($S0)
+ name = new 'PAST::Var'
+ name.'init'('node'=>node, 'name'=>$S0, 'scope'=>'lexical', 'ismy'=>1,
'islvalue'=>1)
+ explist = new .ResizablePMCArray
+ $P0 = node['expression']
+ .local pmc iter
+ iter = new .Iterator, $P0
+ L1:
+ unless iter goto L2
+ $P0 = shift iter
+ $P1 = tree.'get'('past', $P0, 'Lua::Grammar::expression')
+ push explist, $P1
+ goto L1
+ L2:
+ .return name.'new'('PAST::Op', name, explist, 'node'=>node,
'pasttype'=>'fornum')
}
transform past (Lua::Grammar::forlist) :language('PIR') {
- internal_error("not implemented (forlist)")
+ .local pmc past, namelist, explist
+ .local pmc symbtab
+ symbtab = get_hll_global ['Lua::PAST'], '$symbtab'
+ namelist = new .ResizablePMCArray
+ $P0 = node['name_list']
+ $P0 = $P0['name']
+ .local pmc iter
+ iter = new .Iterator, $P0
+ L1:
+ unless iter goto L2
+ $P0 = shift iter
+ $S0 = $P0.'result_object'()
+ symbtab.'insert'($S0)
+ past = new 'PAST::Var'
+ past.'init'('node'=>node, 'name'=>$S0, 'scope'=>'lexical', 'ismy'=>1,
'islvalue'=>1)
+ push namelist, past
+ goto L1
+ L2:
+ $P0 = node['expression_list']
+ explist = tree.'get'('explist', $P0, 'Lua::Grammar::expression_list')
+ .return past.'new'('PAST::Op', namelist, explist, 'node'=>node,
'pasttype'=>'forlist')
}
@@ -150,29 +197,31 @@
transform past (Lua::Grammar::local_declaration) :language('PIR') {
- .local pmc past
- .local pmc namelist, explist
+ .local pmc past, namelist, explist
+ .local pmc symbtab
+ symbtab = get_hll_global ['Lua::PAST'], '$symbtab'
$P0 = node['name']
namelist = new .ResizablePMCArray
.local pmc iter
iter = new .Iterator, $P0
-L1:
+ L1:
unless iter goto L2
$P0 = shift iter
$S0 = $P0.'result_object'()
+ symbtab.'insert'($S0)
past = new 'PAST::Var'
past.'init'('node'=>node, 'name'=>$S0, 'scope'=>'lexical', 'ismy'=>1,
'islvalue'=>1)
push namelist, past
goto L1
-L2:
+ L2:
$P0 = node['expression_list']
if null $P0 goto L3
$P0 = shift $P0
explist = tree.'get'('explist', $P0, 'Lua::Grammar::expression_list')
-L3:
+ L3:
unless null explist goto L4
explist = new .ResizablePMCArray
-L4:
+ L4:
past = new 'PAST::Op'
past.'init'(namelist, explist, 'node'=>node, 'pasttype'=>'assignlist')
.return (past)
@@ -181,10 +230,13 @@
transform past (Lua::Grammar::local_function) :language('PIR') {
.local pmc past, var
+ .local pmc symbtab
+ symbtab = get_hll_global ['Lua::PAST'], '$symbtab'
$P0 = node['function_body']
past = tree.'get'('past', $P0, 'Lua::Grammar::function_body')
$P0 = node['name']
$S0 = $P0.'result_object'()
+ symbtab.'insert'($S0)
past.'name'($S0)
var = past.'new'('PAST::Var', 'node'=>$P0, 'name'=>$S0,
'scope'=>'lexical', 'ismy'=>1, 'islvalue'=>1)
.return past.'new'('PAST::Op', var, past, 'node'=>node,
'pasttype'=>'assign')
@@ -200,7 +252,7 @@
$P1 = tree.'get'('explist', $P0, 'Lua::Grammar::expression_list')
past.'init'($P1 :flat, 'node'=>node, 'pasttype'=>'pirop',
'pirop'=>'return')
.return (past)
-L1:
+ L1:
past.'init'('node'=>node, 'pasttype'=>'pirop', 'pirop'=>'return')
.return (past)
}
@@ -219,7 +271,7 @@
unless null $P0 goto L1
$P0 = node['primary_expression']
.return tree.'get'('past', $P0, 'Lua::Grammar::primary_expression')
-L1:
+ L1:
.local pmc varlist, explist
$P0 = shift $P0
explist = tree.'get'('explist', $P0, 'Lua::Grammar::assignment')
@@ -241,7 +293,7 @@
if null $P0 goto L1
varlist = new .ResizablePMCArray
.return (varlist)
-L1:
+ L1:
$P0 = node['assignment']
varlist = tree.'get'('varlist', $P0, 'Lua::Grammar::assignment')
$P0 = node['primary_expression']
@@ -256,7 +308,7 @@
$P0 = node['expression_list']
if null $P0 goto L1
.return tree.'get'('explist', $P0, 'Lua::Grammar::expression_list')
-L1:
+ L1:
$P0 = node['assignment']
.return tree.'get'('explist', $P0, 'Lua::Grammar::assignment')
}
@@ -270,19 +322,19 @@
explist = new .ResizablePMCArray
push explist, past
.return (explist)
-L1:
+ L1:
$P0 = node['string']
if null $P0 goto L2
past = tree.'get'('past', $P0, 'Lua::Grammar::string')
explist = new .ResizablePMCArray
push explist, past
.return (explist)
-L2:
+ L2:
$P0 = node['expression_list']
unless null $P0 goto L3
explist = new .ResizablePMCArray
.return (explist)
-L3:
+ L3:
$P0 = shift $P0
.return tree.'get'('explist', $P0, 'Lua::Grammar::expression_list')
}
@@ -295,10 +347,13 @@
$S0 = $P0.'result_object'()
$I0 = index $S0, ':'
if $I0 < 0 goto L1
+ .local pmc symbtab
+ symbtab = get_hll_global ['Lua::PAST'], '$symbtab'
+ symbtab.'insert'('self')
past = new 'PAST::Var'
past.'init'('node'=>$P0, 'name'=>'self', 'scope'=>'parameter')
set_hll_global ['Lua::PAST'], '$?self', past
-L1:
+ L1:
$P0 = node['function_body']
past = tree.'get'('past', $P0, 'Lua::Grammar::function_body')
past.'name'($S0)
@@ -314,14 +369,14 @@
$S0 = $P0.'result_object'()
past = new 'PAST::Var'
past.'init'('node'=>node, 'name'=>$S0, 'scope'=>'package')
-L2:
+ L2:
unless iter goto L1
$P0 = shift iter
$S0 = $P0.'result_object'()
key = past.'new'('PAST::Val', 'node'=>$P0, 'vtype'=>'.LuaString',
'name'=>$S0, 'ctype'=>'s~')
past = past.'new'('PAST::Var', past, key, 'node'=>node, 'scope'=>'keyed')
goto L2
-L1:
+ L1:
past.'islvalue'(1)
.return (past)
}
@@ -329,13 +384,15 @@
transform past (Lua::Grammar::function_body) :language('PIR') {
.local pmc past, parlist, var
+ .local pmc symbtab
+ symbtab = get_hll_global ['Lua::PAST'], '$symbtab'
parlist = new .ResizablePMCArray
var = get_hll_global ['Lua::PAST'], '$?self'
if null var goto L1
push parlist, var
null var
set_hll_global ['Lua::PAST'], '$?self', var
-L1:
+ L1:
$P0 = node['parameter_list']
if null $P0 goto L2
$P0 = shift $P0
@@ -344,25 +401,27 @@
$P1 = $P1['name']
.local pmc iter
iter = new .Iterator, $P1
-L4:
+ L4:
unless iter goto L3
$P1 = shift iter
$S0 = $P1.'result_object'()
+ symbtab.'insert'($S0)
var = new 'PAST::Var'
var.'init'('node'=>$P1, 'name'=>$S0, 'scope'=>'parameter')
push parlist, var
goto L4
-L3:
+ L3:
$P1 = $P0['vararg']
if null $P1 goto L2
$P1 = shift $P1
var = new 'PAST::Var'
var.'init'('node'=>$P1, 'name'=>'...', 'scope'=>'parameter', 'isslurpy'=>1)
push parlist, var
-L2:
+ L2:
$P0 = node['block']
past = tree.'get'('past', $P0, 'Lua::Grammar::block')
- .return past.'new'('PAST::Block', parlist :flat, past, 'node'=>node,
'pragma'=>':anon :lex')
+ $P0 = new 'Lua::Symbtab'
+ .return past.'new'('PAST::Block', parlist :flat, past, 'node'=>node,
'symtable'=>$P0, 'pragma'=>':anon :lex')
}
@@ -377,7 +436,7 @@
.local pmc iter, key, expr, var
$I0 = 1
iter = new .Iterator, $P0
-L2:
+ L2:
unless iter goto L1
$P0 = shift iter
$S0 = $P0.'find_key'()
@@ -386,12 +445,12 @@
$P1 = tree.'get'('past', $P0, 'Lua::Grammar::expression')
past.'push'($P1)
goto L2
-L3:
+ L3:
$S0 = concat 'Lua::Grammar::', $S0
$P1 = tree.'get'('record', $P0, $S0)
past.'push'($P1)
goto L2
-L1:
+ L1:
.return (past)
}
@@ -433,13 +492,13 @@
$P0 = node['expression']
.local pmc iter
iter = new .Iterator, $P0
-L1:
+ L1:
unless iter goto L2
$P0 = shift iter
$P1 = tree.'get'('past', $P0, 'Lua::Grammar::expression')
push explist, $P1
goto L1
-L2:
+ L2:
.return (explist)
}
@@ -458,7 +517,7 @@
$P0 = node[$S0]
$S0 = concat 'Lua::Grammar::', $S0
.return tree.'get'('past', $P0, $S0)
-L1:
+ L1:
.local pmc optable, optok
.local string pirop, returns
optable = get_hll_global [ 'Lua::Grammar' ], '$optable'
@@ -470,20 +529,20 @@
returns = optok['returns']
past.'init'('node'=>node, 'name'=>type, 'pasttype'=>'pirop',
'pirop'=>pirop, 'returns'=>returns)
goto L3
-L2:
+ L2:
$S0 = optok['past']
past.'init'('node'=>node, 'name'=>type, 'pasttype'=>$S0)
-L3:
+ L3:
$P0 = node.'get_array'()
.local pmc iter
iter = new .Iterator, $P0
-L5:
+ L5:
unless iter goto L4
$P0 = shift iter
$P1 = tree.'get'('past', $P0, 'Lua::Grammar::expr')
past.'push'($P1)
goto L5
-L4:
+ L4:
.return (past)
}
@@ -504,30 +563,30 @@
$P0 = node['name']
if null $P0 goto L1
iter = new .Iterator, $P0
-L2:
+ L2:
unless iter goto L1
$P0 = shift iter
key = tree.'get'('key', $P0, 'Lua::Grammar::name')
past = past.'new'('PAST::Var', past, key, 'node'=>node, 'scope'=>'keyed')
goto L2
-L1:
+ L1:
$P0 = node['index']
if null $P0 goto L3
iter = new .Iterator, $P0
-L4:
+ L4:
unless iter goto L3
$P0 = shift iter
key = tree.'get'('key', $P0, 'Lua::Grammar::index')
past = past.'new'('PAST::Var', past, key, 'node'=>node, 'scope'=>'keyed')
goto L4
-L3:
+ L3:
$P0 = node['function_args']
unless null $P0 goto L9
.return (past)
-L9:
+ L9:
$P0 = shift $P0
$P1 = tree.'get'('explist', $P0, 'Lua::Grammar::function_args')
.return past.'new'('PAST::Op', past, $P1 :flat, 'node'=>node,
'pasttype'=>'call')
@@ -544,8 +603,15 @@
transform past (Lua::Grammar::name) :language('PIR') {
.local pmc past
+ .local pmc symbtab
+ symbtab = get_hll_global ['Lua::PAST'], '$symbtab'
$S0 = node.'result_object'()
past = new 'PAST::Var'
+ $I0 = symbtab.'lookup'($S0)
+ unless $I0 goto L1
+ past.'init'('node'=>node, 'name'=>$S0, 'scope'=>'lexical')
+ .return (past)
+ L1:
past.'init'('node'=>node, 'name'=>$S0, 'scope'=>'package')
.return (past)
}
Modified: trunk/languages/lua/src/POSTGrammar.tg
==============================================================================
--- trunk/languages/lua/src/POSTGrammar.tg (original)
+++ trunk/languages/lua/src/POSTGrammar.tg Mon Jun 4 00:55:03 2007
@@ -227,38 +227,31 @@
transform if (PAST::Op) :language('PIR') {
- .local pmc ops
+ .local pmc ops, expr, then, else
ops = new 'POST::Ops'
ops.'init'('node'=>node)
-
- .local pmc exprpast, thenpast, elsepast
- .local pmc exprpost, thenpost, elsepost
- exprpast = node[0]
- thenpast = node[1]
- elsepast = node[2]
-
.local pmc thenlabel, endlabel
- .local string n
- n = node.'unique'('_')
- $S0 = concat 'if', n
+ $S0 = node.'unique'('if_')
thenlabel = ops.'new'('POST::Label', 'result'=>$S0)
$S0 = concat $S0, '_end'
endlabel = ops.'new'('POST::Label', 'result'=>$S0)
-
- exprpost = tree.'get'('post', exprpast)
- ops.'push'(exprpost)
- ops.'push_pirop'('if', exprpost, thenlabel)
- $I0 = defined elsepast
+ $P0 = node[0]
+ expr = tree.'get'('post', $P0)
+ ops.'push'(expr)
+ ops.'push_pirop'('if', expr, thenlabel)
+ $P0 = node[2]
+ $I0 = defined $P0
if $I0 == 0 goto else_done
- elsepost = tree.'get'('post', elsepast)
- ops.'push'(elsepost)
+ else = tree.'get'('post', $P0)
+ ops.'push'(else)
else_done:
ops.'push_pirop'('goto', endlabel)
ops.'push'(thenlabel)
- $I0 = defined thenpast
+ $P0 = node[1]
+ $I0 = defined $P0
if $I0 == 0 goto then_done
- thenpost = tree.'get'('post', thenpast)
- ops.'push'(thenpost)
+ then = tree.'get'('post', $P0)
+ ops.'push'(then)
then_done:
ops.'push'(endlabel)
.return (ops)
@@ -266,32 +259,113 @@
transform while (PAST::Op) :language('PIR') {
- .local pmc ops
+ .local pmc ops, expr, blk
ops = new 'POST::Ops'
ops.'init'('node'=>node)
+ .local pmc looplabel, endlabel
+ $S0 = node.'unique'('while_')
+ looplabel = ops.'new'('POST::Label', 'result'=>$S0)
+ $S0 = concat $S0, '_end'
+ endlabel = ops.'new'('POST::Label', 'result'=>$S0)
+ ops.'push'(looplabel)
+ $P0 = node[0]
+ expr = tree.'get'('post', $P0)
+ ops.'push'(expr)
+ ops.'push_pirop'('unless', expr, endlabel)
+ $P0 = node[1]
+ blk = tree.'get'('post', $P0)
+ ops.'push'(blk)
+ ops.'push_pirop'('goto', looplabel)
+ ops.'push'(endlabel)
+ .return (ops)
+}
- .local pmc exprpast, blockpast
- .local pmc exprpost, blockpost
- exprpast = node[0]
- blockpast = node[1]
+transform repeat (PAST::Op) :language('PIR') {
+ .local pmc ops, expr, blk
+ ops = new 'POST::Ops'
+ ops.'init'('node'=>node)
.local pmc looplabel, endlabel
- .local string n
- n = node.'unique'('_')
- $S0 = concat 'while', n
+ $S0 = node.'unique'('repeat_')
looplabel = ops.'new'('POST::Label', 'result'=>$S0)
$S0 = concat $S0, '_end'
endlabel = ops.'new'('POST::Label', 'result'=>$S0)
-
ops.'push'(looplabel)
- exprpost = tree.'get'('post', exprpast)
- ops.'push'(exprpost)
- ops.'push_pirop'('unless', exprpost, endlabel)
- blockpost = tree.'get'('post', blockpast)
- ops.'push'(blockpost)
+ $P0 = node[1]
+ blk = tree.'get'('post', $P0)
+ ops.'push'(blk)
+ $P0 = node[0]
+ expr = tree.'get'('post', $P0)
+ ops.'push'(expr)
+ ops.'push_pirop'('if', expr, endlabel)
ops.'push_pirop'('goto', looplabel)
ops.'push'(endlabel)
- ops.'result'(exprpost)
+ .return (ops)
+}
+
+
+transform fornum (PAST::Op) :language('PIR') {
+ internal_error("not implemented (fornum)")
+ .local pmc ops, var, limit, step, blk
+ ops = new 'POST::Ops'
+ ops.'init'('node'=>node)
+
+ $P0 = node[1]
+ $P1 = $P0[0]
+ $P2 = tree.'get'('post', $P1)
+ ops.'push'($P2)
+ var = ops.'push_pirop'('new')
+ var.'arglist'(var, '.LuaNil')
+# ops.'push_pirop'('set', var, $P2)
+
+ $P1 = $P0[1]
+ $P2 = tree.'get'('post', $P1)
+ ops.'push'($P2)
+ limit = ops.'push_pirop'('new')
+ limit.'arglist'(limit, '.LuaNil')
+# ops.'push_pirop'('set', limit, $P2)
+
+ $P1 = $P0[2]
+ if $P1 goto L1
+ goto L2
+ $P2 = ops.'push_pirop'('new')
+ $P2.'arglist'($P2, '.LuaNumber')
+ $P2 = ops.'push_pirop'('set', $P2, '1', 'result'=>$P2)
+ #ops.'result'($P2)
+ L1:
+ $P2 = tree.'get'('post', $P1)
+ ops.'push'($P2)
+ L2:
+ step = ops.'push_pirop'('new')
+ step.'arglist'(step, '.LuaNil')
+# ops.'push_pirop'('set', step, $P2)
+
+ .local pmc looplabel, endlabel
+ $S0 = node.'unique'('fornum_')
+ looplabel = ops.'new'('POST::Label', 'result'=>$S0)
+ $S0 = concat $S0, '_end'
+ endlabel = ops.'new'('POST::Label', 'result'=>$S0)
+ ops.'push'(looplabel)
+
+ ops.'push'(endlabel)
+ .return (ops)
+}
+
+
+transform forlist (PAST::Op) :language('PIR') {
+ internal_error("not implemented (forlist)")
+ .local pmc ops, var, limit, step, blk
+ ops = new 'POST::Ops'
+ ops.'init'('node'=>node)
+
+ .local pmc looplabel, endlabel
+ $S0 = node.'unique'('forlist_')
+ looplabel = ops.'new'('POST::Label', 'result'=>$S0)
+ $S0 = concat $S0, '_end'
+ endlabel = ops.'new'('POST::Label', 'result'=>$S0)
+ ops.'push'(looplabel)
+
+ ops.'push'(endlabel)
.return (ops)
}
@@ -323,19 +397,19 @@
rpost = tree.'get'('post', $P1)
ops.'push'(rpost)
goto L3
-L2:
+ L2:
rpost = ops.'push_pirop'('new')
rpost.'arglist'(rpost, '.LuaNil')
-L3:
+ L3:
$P0 = namelist[0]
lpost = tree.'get'('post', $P0)
ops.'push'(lpost)
ops.'push_pirop'('set', lpost, rpost)
.return (ops)
-L1:
+ L1:
.local pmc iter
new iter, .Iterator, namelist
-L4:
+ L4:
unless iter goto L5
$P0 = shift iter
unless explist goto L6
@@ -343,15 +417,15 @@
rpost = tree.'get'('post', $P1)
ops.'push'(rpost)
goto L7
-L6:
+ L6:
rpost = ops.'push_pirop'('new')
rpost.'arglist'(rpost, '.LuaNil')
-L7:
+ L7:
lpost = tree.'get'('post', $P0)
ops.'push'(lpost)
ops.'push_pirop'('set', lpost, rpost)
goto L4
-L5:
+ L5:
.return (ops)
}
@@ -465,13 +539,20 @@
goto have_scope
scope_lexical:
- fetchop = 'find_lex'
- storeop = 'store_lex'
$I0 = node.'ismy'()
- if $I0 == 0 goto have_scope
+ if $I0 == 0 goto L1
post.'push'(vivipost)
post.'push_pirop'('.lex', name, vivipost)
.return (post)
+ L1:
+ $I0 = node.'islvalue'()
+ unless $I0 goto L2
+ post.'push_pirop'('store_lex', name, post)
+ .return (post)
+ L2:
+ post.'push_pirop'('find_lex', vivipost, name)
+ post.'result'(post)
+ .return (post)
scope_parameter:
post = new 'POST::Op'
Modified: trunk/languages/lua/src/lua51.pir
==============================================================================
--- trunk/languages/lua/src/lua51.pir (original)
+++ trunk/languages/lua/src/lua51.pir Mon Jun 4 00:55:03 2007
@@ -96,7 +96,7 @@
.param string message :optional
unless null message goto L1
message = 'syntax error'
-L1:
+ L1:
lexerror(mob, message)
.end
@@ -122,7 +122,7 @@
$S0 .= " near '"
$S0 .= $S1
$S0 .= "'"
-L1:
+ L1:
.local pmc ex
ex = new .Exception
ex['_message'] = $S0
@@ -171,7 +171,7 @@
if $S0 == '_' goto L1
$I0 = is_cclass .CCLASS_ALPHABETIC, target, pos
if $I0 == 0 goto L2
-L1:
+ L1:
$I0 = pos
pos = find_not_cclass .CCLASS_WORD, target, pos, lastpos
$I1 = pos - $I0
@@ -181,11 +181,11 @@
unless null kw goto L3
kw = _const_keyword()
set_hll_global 'keyword', kw
-L3:
+ L3:
$I0 = exists kw[$S0]
if $I0 goto L2
mpos = pos
-L2:
+ L2:
.return (mob)
.end
@@ -239,7 +239,7 @@
target = mob.'text'()
lastpos = length target
-L_alt1: # 0 [Xx] <xdigit>+
+ L_alt1: # 0 [Xx] <xdigit>+
pos = 0
$S0 = substr target, pos, 1
unless $S0 == '0' goto L_alt2
@@ -252,7 +252,7 @@
if $I0 == 0 goto L_alt2
pos = find_not_cclass .CCLASS_HEXADECIMAL, target, pos, lastpos
goto L_end
-L_alt2: # <digit>+ [\.]?
+ L_alt2: # <digit>+ [\.]?
pos = 0
$I0 = is_cclass .CCLASS_NUMERIC, target, pos
if $I0 == 0 goto L_alt3
@@ -261,16 +261,16 @@
unless $S0 == '.' goto L_opt2
inc pos
goto L_opt1
-L_alt3: # \. <digit>
+ L_alt3: # \. <digit>
pos = 0
$S0 = substr target, pos, 1
unless $S0 == '.' goto L_end
inc pos
$I0 = is_cclass .CCLASS_NUMERIC, target, pos
if $I0 == 0 goto L_end
-L_opt1: # <digit>*
+ L_opt1: # <digit>*
pos = find_not_cclass .CCLASS_NUMERIC, target, pos, lastpos
-L_opt2: # [Ee] [+\-]? <digit>+
+ L_opt2: # [Ee] [+\-]? <digit>+
.local int pos2
pos2 = pos
$S0 = substr target, pos2, 1
@@ -281,14 +281,14 @@
$I0 = index '+-', $S0
if $I0 < 0 goto L_opt3
inc pos2
-L_opt3:
+ L_opt3:
$I0 = is_cclass .CCLASS_NUMERIC, target, pos2
if $I0 == 0 goto L_end
pos = find_not_cclass .CCLASS_NUMERIC, target, pos2, lastpos
-L_end:
+ L_end:
if pos == lastpos goto L1
lexerror(mob, 'malformed number')
-L1:
+ L1:
.return (mob)
.end
@@ -308,11 +308,11 @@
$S0 = substr target, pos, 1
unless $S0 == '.' goto L1
inc pos
-L1:
+ L1:
$I0 = is_cclass .CCLASS_NUMERIC, target, pos
if $I0 == 0 goto L2
inc pos
-L3:
+ L3:
$I0 = is_cclass .CCLASS_NUMERIC, target, pos
if $I0 == 0 goto L4
pos = find_not_cclass .CCLASS_NUMERIC, target, pos, lastpos
@@ -320,12 +320,12 @@
unless $S0 == '.' goto L5
inc pos
goto L3
-L4:
+ L4:
$S0 = substr target, pos, 1
unless $S0 == '.' goto L5
inc pos
goto L3
-L5:
+ L5:
$S0 = substr target, pos, 1
$I0 = index 'Ee', $S0
if $I0 < 0 goto L6
@@ -334,11 +334,11 @@
$I0 = index '+-', $S0
if $I0 < 0 goto L6
inc pos
-L6:
+ L6:
$I0 = .CCLASS_NUMERIC | .CCLASS_WORD
pos = find_not_cclass $I0, target, pos, lastpos
mpos = pos
-L2:
+ L2:
.return (mob)
.end
@@ -380,22 +380,22 @@
.local string literal
literal = ''
-LOOP:
+ LOOP:
if pos < lastpos goto L1
mpos = pos
lexerror(mob, "unfinished string")
-L1:
+ L1:
$S0 = substr target, pos, 1
if $S0 != delim goto L2
mob.'result_object'(literal)
mpos = pos
.return (mob)
-L2:
+ L2:
$I0 = index "\n\r", $S0
if $I0 < 0 goto L3
mpos = pos
lexerror(mob, "unfinished string")
-L3:
+ L3:
if $S0 != "\\" goto CONCAT
inc pos
if pos == lastpos goto LOOP # error
@@ -404,12 +404,12 @@
if $I0 < 0 goto L4
$S0 = substr "\a\b\f\n\r\t\x0b", $I0, 1
goto CONCAT
-L4:
+ L4:
$I0 = index "\n\r", $S0
if $I0 < 0 goto L5
$S0 = "\n"
goto CONCAT
-L5:
+ L5:
$I0 = index '0123456789', $S0
if $I0 < 0 goto CONCAT
inc pos
@@ -425,16 +425,16 @@
$I0 *= 10
$I0 += $I1
goto L7
-L6:
+ L6:
dec pos
-L7:
+ L7:
if $I0 < 256 goto L8
mpos = pos
lexerror(mob, "escape sequence too large")
-L8:
+ L8:
$S0 = chr $I0
-CONCAT:
+ CONCAT:
concat literal, $S0
inc pos
goto LOOP
@@ -492,20 +492,20 @@
if sep == -1 goto END
mpos = pos
lexerror(mob, "invalid long string delimiter")
-L1:
+ L1:
inc pos
$S0 = substr target, pos, 1
$I0 = index "\n\r", $S0
if $I0 < 0 goto L2
inc pos
-L2:
+ L2:
.local string literal
literal = ''
-LOOP:
+ LOOP:
if pos < lastpos goto L3
lexerror(mob, "unfinished long string")
-L3:
+ L3:
$S0 = substr target, pos, 1
if $S0 != '[' goto L4
inc pos
@@ -514,10 +514,10 @@
inc pos
mpos = pos
lexerror(mob, "nesting of [[...]] is deprecated")
-L5:
+ L5:
dec pos
goto CONCAT
-L4:
+ L4:
if $S0 != ']' goto L6
inc pos
($I0, $I1) = _skip_sep(target, pos, ']')
@@ -526,22 +526,22 @@
mob.'result_object'(literal)
mpos = pos
goto END
-L7:
+ L7:
dec pos
goto CONCAT
-L6:
+ L6:
$I0 = index "\n\r", $S0
if $I0 < 0 goto L8
$S0 = "\n"
goto CONCAT
-L8:
+ L8:
-CONCAT:
+ CONCAT:
concat literal, $S0
inc pos
goto LOOP
-END:
+ END:
.return (mob)
.end
@@ -579,14 +579,14 @@
# $I0 = index "\n\r", $S0
# if $I0 < 0 goto L2
# inc pos
-#L2:
+# L2:
# .local string literal
# literal = ''
-LOOP:
+ LOOP:
if pos < lastpos goto L3
lexerror(mob, "unfinished long comment")
-L3:
+ L3:
$S0 = substr target, pos, 1
if $S0 != '[' goto L4
inc pos
@@ -595,10 +595,10 @@
inc pos
mpos = pos
lexerror(mob, "nesting of [[...]] is deprecated")
-L5:
+ L5:
dec pos
goto CONCAT
-L4:
+ L4:
if $S0 != ']' goto L6
inc pos
($I0, $I1) = _skip_sep(target, pos, ']')
@@ -607,22 +607,22 @@
# mob.'result_object'(literal)
mpos = pos
goto END
-L7:
+ L7:
dec pos
goto CONCAT
-L6:
+ L6:
$I0 = index "\n\r", $S0
if $I0 < 0 goto L8
# $S0 = "\n"
goto CONCAT
-L8:
+ L8:
-CONCAT:
+ CONCAT:
# concat literal, $S0
inc pos
goto LOOP
-END:
+ END:
.return (mob)
.end
@@ -632,17 +632,17 @@
.param string delim
.local int count
count = 0
-L1:
+ L1:
$S0 = substr target, pos, 1
if $S0 != '=' goto L2
inc count
inc pos
goto L1
-L2:
+ L2:
if $S0 == delim goto L3
neg count
dec count
-L3:
+ L3:
.return (pos, count)
.end
@@ -651,7 +651,7 @@
=item C<internal_error>
-used in F<languages/lua/src/ASTGrammar.tg>
+used in F<languages/lua/src/PASTGrammar.tg>
=cut
@@ -663,6 +663,24 @@
exit 1
.end
+
+.namespace [ 'Lua::POST::Grammar' ]
+
+=item C<internal_error>
+
+used in F<languages/lua/src/POSTGrammar.tg>
+
+=cut
+
+.sub internal_error
+ .param string msg
+ $S0 = "ERROR_INTERNAL (POST): " . msg
+ $S0 .= "\n"
+ printerr $S0
+ exit 1
+.end
+
+
.namespace [ "Lua::POST" ]
.sub '__onload' :load :init
@@ -690,6 +708,7 @@
.return ()
.end
+
.namespace [ "Lua::POST::Chunk" ]
.sub 'prologue' :method
@@ -708,9 +727,26 @@
$P0 = get_hll_global ['POST'], '$!subpir'
code .= $P0
set_hll_global ['POST'], '$!subpir', code
-L1:
+ L1:
+.end
+
+
+.namespace [ "Lua::Symbtab" ]
+
+.sub '__onload' :load :init
+ $P0 = subclass 'Hash', 'Lua::Symbtab'
.end
+.sub 'insert' :method
+ .param string name
+ self[name] = 1
+.end
+
+.sub 'lookup' :method
+ .param string name
+ $I0 = exists self[name]
+ .return ($I0)
+.end
.include 'languages/lua/src/lua51_gen.pir'
.include 'languages/lua/src/PASTGrammar_gen.pir'