Skip to content

Loading…

Removed optimization from transform return #3

Merged
merged 3 commits into from

2 participants

@dafrito

This is a one-commit fix removes an optimization that breaks some specially crafted tables. I wasn't
sure how to correct it without removing it.


This optimization would normally remove an unnecessary variable, such as
the one in the following generated PIR:

set $P18, $P17[k_Foo]
new $P19, "LuaNil"
.tailcall $P18()

In the above snippet, $P19 is not used, so it can be removed without
harm. However, there are instances where this variable is used. Consider
the following code:

function Foo()
return 42
end

return { Foo() }

In this case, the following PIR should be generated:

new $P21, "LuaNil"
($P21 :slurpy) = $P20()
.tailcall tconstruct($P18, $P19, $P21 :flat)

In this case, the register that initially contains a nil value is
actually used, so it cannot be optimized away.

dafrito added some commits
@dafrito dafrito transform return: Removed an optimization that broke some table literals
This optimization would normally remove an unnecessary variable, such as
the one in the following generated PIR:

set $P18, $P17[k_Foo]
new $P19, "LuaNil"
.tailcall $P18()

In the above snippet, $P19 is not used, so it can be removed without
harm. However, there are instances where this variable is used. Consider
the following code:

function Foo()
	return 42
end

return { Foo() }

In this case, the following PIR should be generated:

new $P21, "LuaNil"
($P21 :slurpy) = $P20()
.tailcall tconstruct($P18, $P19, $P21 :flat)

In this case, the register that initially contains a nil value is
actually used, so it cannot be optimized away.
8ea8e82
@dafrito dafrito luaaux.pir: Changed encoding to utf8
This fixes a "Lossy conversion to single byte encoding" error when
trying to run a Lua program with Unicode characters.

A simple test is the following snippet:

print "∙";
ee17af1
@dafrito dafrito Allow installable_luap to display Unicode characters
installable_luap fails to display Unicode characters. Consider the following snippet:

print "∙";

This yields the following error:

./installable_luap Unicode.lua
Invalid character in ASCII string
current instr.: 'parrot;PCT;HLLCompiler;evalfiles' pc 1468 (compilers/pct/src/PCT/HLLCompiler.pir:756)
called from Sub 'parrot;PCT;HLLCompiler;command_line' pc 1719 (compilers/pct/src/PCT/HLLCompiler.pir:875)
called from Sub 'main' pc 27 (luap.pir:27)

This patch fixes the problem for installable_luap, but it remains for installable_lua
fcf40ee
@fperrad fperrad merged commit 3806339 into fperrad:master
@fperrad
Owner

merged, thanks.

@dafrito

Sorry that some Unicode commits snuck in this branch. I knew I shouldn't have been working off master; I'll work in separate feature branches for future pull requests.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Aug 3, 2011
  1. @dafrito

    transform return: Removed an optimization that broke some table literals

    dafrito committed
    This optimization would normally remove an unnecessary variable, such as
    the one in the following generated PIR:
    
    set $P18, $P17[k_Foo]
    new $P19, "LuaNil"
    .tailcall $P18()
    
    In the above snippet, $P19 is not used, so it can be removed without
    harm. However, there are instances where this variable is used. Consider
    the following code:
    
    function Foo()
    	return 42
    end
    
    return { Foo() }
    
    In this case, the following PIR should be generated:
    
    new $P21, "LuaNil"
    ($P21 :slurpy) = $P20()
    .tailcall tconstruct($P18, $P19, $P21 :flat)
    
    In this case, the register that initially contains a nil value is
    actually used, so it cannot be optimized away.
  2. @dafrito

    luaaux.pir: Changed encoding to utf8

    dafrito committed
    This fixes a "Lossy conversion to single byte encoding" error when
    trying to run a Lua program with Unicode characters.
    
    A simple test is the following snippet:
    
    print "∙";
Commits on Aug 4, 2011
  1. @dafrito

    Allow installable_luap to display Unicode characters

    dafrito committed
    installable_luap fails to display Unicode characters. Consider the following snippet:
    
    print "∙";
    
    This yields the following error:
    
    ./installable_luap Unicode.lua
    Invalid character in ASCII string
    current instr.: 'parrot;PCT;HLLCompiler;evalfiles' pc 1468 (compilers/pct/src/PCT/HLLCompiler.pir:756)
    called from Sub 'parrot;PCT;HLLCompiler;command_line' pc 1719 (compilers/pct/src/PCT/HLLCompiler.pir:875)
    called from Sub 'main' pc 27 (luap.pir:27)
    
    This patch fixes the problem for installable_luap, but it remains for installable_lua
Showing with 2 additions and 6 deletions.
  1. +0 −4 lua/POSTGrammar.tg
  2. +1 −1 lua/lib/luaaux.pir
  3. +1 −1 luap.pir
View
4 lua/POSTGrammar.tg
@@ -716,10 +716,6 @@ transform return (PAST;Op) :language('PIR') {
unless $I0 goto L3
if arglist goto L4
$P0.'pirop'('tailcall')
- # remove useless new LuaNil
- $P1 = cpost.'pop'()
- $P2 = cpost.'pop'()
- cpost.'push'($P1)
.return (ops)
L4:
$S1 = '(' . $S0
View
2 lua/lib/luaaux.pir
@@ -597,7 +597,7 @@ messages and in debug information.
unless $S0 == "\033Lua" goto L2
.tailcall undump(data, chunkname)
L2:
- $I0 = find_encoding 'ascii'
+ $I0 = find_encoding 'utf8'
$S0 = trans_encoding data, $I0
.tailcall parser($S0, chunkname)
.end
View
2 luap.pir
@@ -24,7 +24,7 @@ with the standard interface of PCT::HLLCompiler.
$P0 = compreg 'lua'
$S0 = "Compiler Lua 5.1 on Parrot Copyright (C) 2005-2009, Parrot Foundation.\n"
$P0.'commandline_banner'($S0)
- $P0.'command_line'(args)
+ $P0.'command_line'(args, 'encoding'=>'utf8')
.end
=head1 AUTHOR
Something went wrong with that request. Please try again.