Author: fperrad
Date: Mon Jan 29 08:02:39 2007
New Revision: 16830

Modified:
   trunk/languages/lua/Lua/build.pm
   trunk/languages/lua/t/function.t
   trunk/languages/lua/t/object.t
   trunk/languages/lua/t/shootout.t

Log:
[Lua]
- fix tail call

Modified: trunk/languages/lua/Lua/build.pm
==============================================================================
--- trunk/languages/lua/Lua/build.pm    (original)
+++ trunk/languages/lua/Lua/build.pm    Mon Jan 29 08:02:39 2007
@@ -1140,7 +1140,10 @@
         my $expr = $exprs->[0];
         if ( scalar $expr->[1] ) {
             my @opcodes = @{ $expr->[1] };
-            if ( scalar @opcodes and $opcodes[-1]->isa('CallOp') ) {
+            if (    scalar @opcodes
+                and $opcodes[-1]->isa('CallOp')
+                and !exists $opcodes[-1]->{result}->[0]->{pragma} )
+            {
                 my $call = pop @opcodes;
                 my $ass = pop @opcodes;
                 my $loc = pop @opcodes;

Modified: trunk/languages/lua/t/function.t
==============================================================================
--- trunk/languages/lua/t/function.t    (original)
+++ trunk/languages/lua/t/function.t    Mon Jan 29 08:02:39 2007
@@ -23,7 +23,7 @@
 use FindBin;
 use lib "$FindBin::Bin";
 
-use Parrot::Test tests => 12;
+use Parrot::Test tests => 14;
 use Test::More;
 
 language_output_is( 'lua', <<'CODE', <<'OUT', 'add' );
@@ -220,6 +220,40 @@
 end    0
 OUT
 
+language_output_is( 'lua', <<'CODE', <<'OUT', 'no tail call' );
+local function foo (n)
+    print(n)
+    if n > 0 then
+        return (foo(n -1))
+    end
+    return 'end', 0
+end
+
+print(foo(3))
+CODE
+3
+2
+1
+0
+end
+OUT
+
+language_output_is( 'lua', <<'CODE', <<'OUT', 'no tail call' );
+local function foo (n)
+    print(n)
+    if n > 0 then
+        foo(n -1)
+    end
+end
+
+foo(3)
+CODE
+3
+2
+1
+0
+OUT
+
 # Local Variables:
 #   mode: cperl
 #   cperl-indent-level: 4

Modified: trunk/languages/lua/t/object.t
==============================================================================
--- trunk/languages/lua/t/object.t      (original)
+++ trunk/languages/lua/t/object.t      Mon Jan 29 08:02:39 2007
@@ -21,7 +21,7 @@
 use FindBin;
 use lib "$FindBin::Bin";
 
-use Parrot::Test tests => 8;
+use Parrot::Test tests => 9;
 use Test::More;
 
 language_output_is( 'lua', <<'CODE', <<'OUT', 'object' );
@@ -164,6 +164,10 @@
 -100
 OUT
 
+TODO:
+{
+    local $TODO = 'pb with tail call ?';
+
 language_output_is( 'lua', <<'CODE', <<'OUT', 'multiple inheritance' );
 -- look up for 'k' in list of tables 'plist'
 local function search (k, plist)
@@ -180,9 +184,69 @@
     -- class will search for each method in the list of its
     -- parents ('arg' is the list of parents)
     setmetatable(c, {__index = function (t, k)
+        return search(k, arg)
+    end})
+
+    -- prepare 'c' to be the metatable of its instance
+    c.__index = c
+
+    -- define a new constructor for this new class
+    function c:new (o)
+        o = o or {}
+        setmetatable(o, c)
+        return o
+    end
+
+    -- return new class
+    return c
+end
+
+Account = {balance = 0}
+function Account:deposit (v)
+    self.balance = self.balance + v
+end
+function Account:withdraw (v)
+    self.balance = self.balance - v
+end
+
+Named = {}
+function Named:getname ()
+    return self.name
+end
+function Named:setname (n)
+    self.name = n
+end
+
+NamedAccount = createClass(Account, Named)
+
+account = NamedAccount:new{name = "Paul"}
+print(account:getname())
+account:deposit(100.00)
+print(account.balance)
+CODE
+Paul
+100
+OUT
+}
+
+language_output_is( 'lua', <<'CODE', <<'OUT', 'multiple inheritance (patched)' 
);
+-- look up for 'k' in list of tables 'plist'
+local function search (k, plist)
+    for i=1, #plist do
+        local v = plist[i][k]  -- try 'i'-th superclass
+        if v then return v end
+    end
+end
+
+function createClass (...)
+    local c = {}  -- new class
+    local arg = {...}
+
+    -- class will search for each method in the list of its
+    -- parents ('arg' is the list of parents)
+    setmetatable(c, {__index = function (t, k)
         -- return search(k, arg)
-        local r = search(k, arg)
-        return r
+        return (search(k, arg))
     end})
 
     -- prepare 'c' to be the metatable of its instance

Modified: trunk/languages/lua/t/shootout.t
==============================================================================
--- trunk/languages/lua/t/shootout.t    (original)
+++ trunk/languages/lua/t/shootout.t    Mon Jan 29 08:02:39 2007
@@ -174,9 +174,14 @@
 #       Symmetrical thread rendez-vous requests

 #

 

+TODO:

+{

+    local $TODO = 'pb with tail call ?';

+

 $code = Parrot::Test::slurp_file(File::Spec->catfile( @dir, 'chameneos.lua' ));

 $out = Parrot::Test::slurp_file(File::Spec->catfile( @dir, 
'chameneos-output.txt' ));

 language_output_is( 'lua', $code, $out, 'chameneos', params => '100' );

+}

 

 #

 #   reverse-complement

Reply via email to