Author: fperrad
Date: Mon Jun 11 22:40:09 2007
New Revision: 18942
Modified:
trunk/languages/lua/src/PASTGrammar.tg
trunk/languages/lua/src/POSTGrammar.tg
trunk/languages/lua/src/lua51.pg
Log:
[Lua]
- PGE/PAST : primary_expression
Modified: trunk/languages/lua/src/PASTGrammar.tg
==============================================================================
--- trunk/languages/lua/src/PASTGrammar.tg (original)
+++ trunk/languages/lua/src/PASTGrammar.tg Mon Jun 11 22:40:09 2007
@@ -24,7 +24,7 @@
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')
+ .return past.'new'('PAST::Block', past, 'node'=>node, 'name'=>'&main')
}
@@ -602,15 +602,14 @@
.return tree.'get'('past', $P0, $S0)
L1:
.local pmc optable, optok
- .local string pirop, returns
+ .local string pirop
optable = get_hll_global [ 'Lua::Grammar' ], '$optable'
optok = optable[type]
pirop = optok['pirop']
.local pmc past
past = new 'PAST::Op'
if pirop == '' goto L2
- returns = optok['returns']
- past.'init'('node'=>node, 'name'=>type, 'pasttype'=>'pirop',
'pirop'=>pirop, 'returns'=>returns)
+ past.'init'('node'=>node, 'name'=>type, 'pasttype'=>'pirop',
'pirop'=>pirop)
goto L3
L2:
$S0 = optok['past']
@@ -639,40 +638,45 @@
transform past (Lua::Grammar::primary_expression) :language('PIR') {
- # INCOMPLETE
- .local pmc past, iter, key
+ .local pmc past
$P0 = node['prefix_expression']
past = tree.'get'('past', $P0, 'Lua::Grammar::prefix_expression')
- $P0 = node['name']
+ $P0 = node['slice_expression']
if null $P0 goto L1
+ .local pmc iter, key, args, obj
iter = new .Iterator, $P0
L2:
unless iter goto L1
$P0 = shift iter
- key = tree.'get'('key', $P0, 'Lua::Grammar::name')
+ $P1 = $P0['function_args']
+ if null $P1 goto L3
+ args = tree.'get'('explist', $P1, 'Lua::Grammar::function_args')
+ $P1 = $P0['name']
+ if null $P1 goto L4
+ key = tree.'get'('key', $P1, 'Lua::Grammar::name')
+ obj = past
past = past.'new'('PAST::Var', past, key, 'node'=>node, 'scope'=>'keyed')
+ past = past.'new'('PAST::Op', past, obj, args :flat, 'node'=>node,
'pasttype'=>'callmethod')
goto L2
- L1:
-
- $P0 = node['index']
- if null $P0 goto L3
- iter = new .Iterator, $P0
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
+ past = past.'new'('PAST::Op', past, args :flat, 'node'=>node,
'pasttype'=>'call')
+ goto L2
L3:
-
- $P0 = node['function_args']
- unless null $P0 goto L9
+ $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')
+ 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')
+ goto L2
+ L6:
+ internal_error("primary expression")
+ L1:
.return (past)
-
- 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')
}
Modified: trunk/languages/lua/src/POSTGrammar.tg
==============================================================================
--- trunk/languages/lua/src/POSTGrammar.tg (original)
+++ trunk/languages/lua/src/POSTGrammar.tg Mon Jun 11 22:40:09 2007
@@ -45,7 +45,7 @@
set_hll_global ['Lua::POST'], '@endlabels', endlabels
unless null outerpost goto no_chunk
.local pmc start
- start = post.'new'('POST::Sub', 'name'=>'__start', 'pragma'=>':main',
'result'=>'')
+ start = post.'new'('POST::Sub', 'name'=>'&start', 'pragma'=>':main',
'result'=>'')
start.'push_pirop'('inline', '# print "start\n"')
start.'push_pirop'('inline', ' load_bytecode
"languages/lua/lib/luabasic.pbc"')
start.'push_pirop'('inline', ' load_bytecode
"languages/lua/lib/luacoroutine.pir"')
@@ -56,14 +56,14 @@
start.'push_pirop'('inline', ' load_bytecode
"languages/lua/lib/luaio.pbc"')
start.'push_pirop'('inline', ' load_bytecode
"languages/lua/lib/luaos.pbc"')
start.'push_pirop'('inline', ' load_bytecode
"languages/lua/lib/luadebug.pbc"')
- start.'push_pirop'('inline', ' .const .Sub main = "_main"')
+ start.'push_pirop'('inline', ' .const .Sub main = "&main"')
start.'push_pirop'('inline', ' $P0 = get_global "_G"')
start.'push_pirop'('inline', ' main."setfenv"($P0)')
start.'push_pirop'('inline', ' docall(main)')
post.'init'('outer'=>start)
.local pmc onload
- onload = post.'new'('POST::Sub', 'name'=>'__onload', 'pragma'=>':anon
:init', 'result'=>'')
- onload.'push_pirop'('inline', ' .const .Sub main = "_main"')
+ onload = post.'new'('POST::Sub', 'name'=>'&onload', 'pragma'=>':anon
:init', 'result'=>'')
+ onload.'push_pirop'('inline', ' .const .Sub main = "&main"')
onload.'push_pirop'('inline', '# print "onload\n"')
.return post.'new'('Lua::POST::Chunk', post, onload, start,
'prologue'=><<'PIRCODE')
.include 'interpinfo.pasm'
Modified: trunk/languages/lua/src/lua51.pg
==============================================================================
--- trunk/languages/lua/src/lua51.pg (original)
+++ trunk/languages/lua/src/lua51.pg Mon Jun 11 22:40:09 2007
@@ -24,6 +24,7 @@
[ <statement> <';'>? ]* [ <last_statement> <';'>? ]?
}
+
rule statement {
| <if_stat>
| <while_stat>
@@ -35,96 +36,116 @@
| <expression_stat>
}
-rule function_stat {
- <'function'> <functionname> <function_body>
-}
-
rule last_statement {
| <return_statement>
| <break_statement>
}
-rule return_statement {
- <'return'> <expression_list>?
+
+rule if_stat {
+ <'if'> <expression> <?then> <block> <elseif_block>* <else_block>? <?end>
}
-token break_statement {
- <'break'>
+rule elseif_block {
+ <'elseif'> <expression> <?then> <block>
}
+rule else_block {
+ <'else'> <block>
+}
+
+
+rule while_stat {
+ <'while'> <expression> <?do> <block> <?end>
+}
+
+
rule do_block {
<'do'> <block> <?end>
}
-rule local_stat {
- <'local'> [ <local_function> | <local_declaration> ]
+
+rule for_stat {
+ <'for'> [ <fornum> | <forlist> ] <for_body>
}
-rule expression_stat {
- <primary_expression> <assignment>?
+rule fornum {
+ <name> <'='> <expression> <?comma> <expression> [ <','> <expression> ]?
}
-rule assignment {
- | <','> <primary_expression> <assignment>
- | <'='> <expression_list>
+rule forlist {
+ <name_list> <?in> <expression_list>
}
-rule while_stat {
- <'while'> <expression> <?do> <block> <?end>
+rule for_body {
+ <?do> <block> <?end>
}
+
rule repeat_stat {
<'repeat'> <block> <?until> <expression>
}
-rule for_body {
- <?do> <block> <?end>
+
+rule function_stat {
+ <'function'> <functionname> <function_body>
}
-rule fornum {
- <name> <'='> <expression> <?comma> <expression> [ <','> <expression> ]?
+rule functionname {
+ <name> [ <'.'> <name> ]* [ <':'> <name> ]?
}
-rule forlist {
- <name_list> <?in> <expression_list>
+rule function_body {
+ <'('> <parameter_list> <?closeparen> <block> <?end>
}
-rule for_stat {
- <'for'> [ <fornum> | <forlist> ] <for_body>
+rule parameter_list {
+ | <name_list> [ <','> <vararg> ]?
+ | <vararg>?
}
-rule if_stat {
- <'if'> <expression> <?then> <block> <elseif_block>* <else_block>? <?end>
+rule name_list {
+ <name> [ <','> <name> ]*
}
-rule elseif_block {
- <'elseif'> <expression> <?then> <block>
+
+rule local_stat {
+ <'local'> [ <local_function> | <local_declaration> ]
}
-rule else_block {
- <'else'> <block>
+rule local_function {
+ <'function'> <name> <function_body>
}
rule local_declaration {
<name> [ <','> <name> ]* [ <'='> <expression_list> ]?
}
-rule local_function {
- <'function'> <name> <function_body>
+
+rule expression_stat {
+ <primary_expression> <assignment>?
}
-rule functionname {
- <name> [ <'.'> <name> ]* [ <':'> <name> ]?
+rule assignment {
+ | <','> <primary_expression> <assignment>
+ | <'='> <expression_list>
}
-rule index {
- <'['> <expression> <?closebracket>
+rule expression_list {
+ <expression> [ <','> <expression> ]*
}
-rule record_field {
- [ <name> | <index> ] <'='> <expression>
+
+rule return_statement {
+ <'return'> <expression_list>?
+}
+
+
+token break_statement {
+ <'break'>
}
+
rule constructor {
<'{'> <tablefieldlist>? <?closebrace>
}
@@ -137,41 +158,35 @@
<record_field> | <expression>
}
-rule parameter_list {
- | <name_list> [ <','> <vararg> ]?
- | <vararg>?
-}
-
-rule function_body {
- <'('> <parameter_list> <?closeparen> <block> <?end>
+rule record_field {
+ [ <name> | <index> ] <'='> <expression>
}
-rule expression_list {
- <expression> [ <','> <expression> ]*
+rule index {
+ <'['> <expression> <?closebracket>
}
-rule name_list {
- <name> [ <','> <name> ]*
-}
-rule function_args {
- | <'('> <expression_list>? <?closeparen>
- | <constructor>
- | <string>
+rule primary_expression {
+ <prefix_expression> <slice_expression>*
}
rule prefix_expression {
- | <name>
| <'('> <expression> <?closeparen>
+ | <name>
}
-rule primary_expression {
- <prefix_expression>
- [ <'.'> <name>
+rule slice_expression {
+ | <'.'> <name>
| <index>
| <':'> <name> <function_args>
| <function_args>
- ]*
+}
+
+rule function_args {
+ | <'('> <expression_list>? <?closeparen>
+ | <constructor>
+ | <string>
}
rule simple_expression {
@@ -278,32 +293,24 @@
rule 'expression' is optable { ... }
proto 'term:' is precedence('=')
- is parsed(&simple_expression) { ... }
+ is parsed(&simple_expression) { ... }
+
+proto 'infix:^' is looser('term:') is pirop('pow')
+ is assoc('right') { ... }
+
+proto 'prefix:not' is looser('infix:^') is pirop('not') { ... }
+proto 'prefix:#' is equiv('prefix:not') is past('len') { ... }
+proto 'prefix:-' is equiv('prefix:not') is pirop('neg') { ... }
-proto 'infix:^' is looser('term:') is pirop('pow') is
assoc('right')
- is returns('.LuaNumber') { ... }
+proto 'infix:*' is looser('prefix:not') is pirop('mul') { ... }
+proto 'infix:/' is equiv('infix:*') is pirop('div') { ... }
+proto 'infix:%' is equiv('infix:*') is pirop('mod') { ... }
-proto 'prefix:not' is looser('infix:^') is pirop('not')
- is returns('.LuaBoolean') { ... }
-proto 'prefix:#' is equiv('prefix:not') is past('len')
- is returns('.LuaNumber') { ... }
-proto 'prefix:-' is equiv('prefix:not') is pirop('neg')
- is returns('.LuaNumber') { ... }
-
-proto 'infix:*' is looser('prefix:not') is pirop('mul')
- is returns('.LuaNumber') { ... }
-proto 'infix:/' is equiv('infix:*') is pirop('div')
- is returns('.LuaNumber') { ... }
-proto 'infix:%' is equiv('infix:*') is pirop('mod')
- is returns('.LuaNumber') { ... }
-
-proto 'infix:+' is looser('infix:*') is pirop('add')
- is returns('.LuaNumber') { ... }
-proto 'infix:-' is equiv('infix:+') is pirop('sub')
- is returns('.LuaNumber') { ... }
+proto 'infix:+' is looser('infix:*') is pirop('add') { ... }
+proto 'infix:-' is equiv('infix:+') is pirop('sub') { ... }
-proto 'infix:..' is looser('infix:+') is pirop('concat') is
assoc('right')
- is returns('.LuaString') { ... }
+proto 'infix:..' is looser('infix:+') is pirop('concat')
+ is assoc('right') { ... }
proto 'infix:<' is looser('infix:..') { ... }
proto 'infix:>' is equiv('infix:<') { ... }