Author: fperrad
Date: Sat Nov 29 07:35:13 2008
New Revision: 33344
Removed:
trunk/languages/lua/src/pmc/luaclosure.pmc
trunk/languages/lua/t/pmc/closure.t
Modified:
trunk/MANIFEST
trunk/languages/lua/config/makefiles/root.in
trunk/languages/lua/doc/status.pod
trunk/languages/lua/src/lib/luaaux.pir
trunk/languages/lua/src/lib/luabasic.pir
trunk/languages/lua/src/lib/luacoroutine.pir
trunk/languages/lua/src/lib/luapackage.pir
trunk/languages/lua/src/lib/luastring.pir
trunk/languages/lua/src/pmc/lua.pmc
trunk/languages/lua/src/pmc/lua_private.h
trunk/languages/lua/src/pmc/luaany.pmc
trunk/languages/lua/src/pmc/luafunction.pmc
trunk/languages/lua/src/pmc/luatable.pmc
trunk/languages/lua/t/pmc/function.t
Log:
[Lua]
- merge LuaFunction & LuaClosure
(see r33193 lexical branch merge)
Modified: trunk/MANIFEST
==============================================================================
--- trunk/MANIFEST (original)
+++ trunk/MANIFEST Sat Nov 29 07:35:13 2008
@@ -1,7 +1,7 @@
# ex: set ro:
# $Id$
#
-# generated by tools/dev/mk_manifest_and_skip.pl Fri Nov 28 22:25:51 2008 UT
+# generated by tools/dev/mk_manifest_and_skip.pl Sat Nov 29 15:22:48 2008 UT
#
# See tools/dev/install_files.pl for documentation on the
# format of this file.
@@ -1822,7 +1822,6 @@
languages/lua/src/pmc/luaany.pmc [lua]
languages/lua/src/pmc/luaboolean.pmc [lua]
languages/lua/src/pmc/luabytecode.pmc [lua]
-languages/lua/src/pmc/luaclosure.pmc [lua]
languages/lua/src/pmc/luafunction.pmc [lua]
languages/lua/src/pmc/luanil.pmc [lua]
languages/lua/src/pmc/luanumber.pmc [lua]
@@ -1878,7 +1877,6 @@
languages/lua/t/os.t [lua]
languages/lua/t/package.t [lua]
languages/lua/t/pmc/boolean.t [lua]
-languages/lua/t/pmc/closure.t [lua]
languages/lua/t/pmc/function.t [lua]
languages/lua/t/pmc/nil.t [lua]
languages/lua/t/pmc/number.t [lua]
Modified: trunk/languages/lua/config/makefiles/root.in
==============================================================================
--- trunk/languages/lua/config/makefiles/root.in (original)
+++ trunk/languages/lua/config/makefiles/root.in Sat Nov 29 07:35:13 2008
@@ -30,7 +30,6 @@
luaany \
luaboolean \
luabytecode \
- luaclosure \
luafunction \
luanil \
luanumber \
@@ -44,7 +43,6 @@
$(PMCDIR)/luaany.pmc \
$(PMCDIR)/luaboolean.pmc \
$(PMCDIR)/luabytecode.pmc \
- $(PMCDIR)/luaclosure.pmc \
$(PMCDIR)/luafunction.pmc \
$(PMCDIR)/luanil.pmc \
$(PMCDIR)/luanumber.pmc \
Modified: trunk/languages/lua/doc/status.pod
==============================================================================
--- trunk/languages/lua/doc/status.pod (original)
+++ trunk/languages/lua/doc/status.pod Sat Nov 29 07:35:13 2008
@@ -140,7 +140,6 @@
=item * string F<languages/lua/src/pmc/luastring.pmc>
=item * function F<languages/lua/src/pmc/luafunction.pmc>
-& F<languages/lua/src/pmc/luaclosure.pmc>
=item * userdata F<languages/lua/src/pmc/luauserdata.pmc>
Modified: trunk/languages/lua/src/lib/luaaux.pir
==============================================================================
--- trunk/languages/lua/src/lib/luaaux.pir (original)
+++ trunk/languages/lua/src/lib/luaaux.pir Sat Nov 29 07:35:13 2008
@@ -436,10 +436,8 @@
.local int res
res = 0
if null val goto L1
- res = isa val, 'LuaClosure'
- if res goto L1
res = isa val, 'LuaFunction'
-L1:
+ L1:
new $P0, 'LuaBoolean'
set $P0, res
.return ($P0)
@@ -481,7 +479,7 @@
if res goto L1
$P0 = val.'tonumber'()
res = isa $P0, 'LuaNumber'
-L1:
+ L1:
new $P0, 'LuaBoolean'
set $P0, res
.return ($P0)
@@ -503,7 +501,7 @@
res = isa val, 'LuaString'
if res goto L1
res = isa val, 'LuaNumber'
-L1:
+ L1:
new $P0, 'LuaBoolean'
set $P0, res
.return ($P0)
Modified: trunk/languages/lua/src/lib/luabasic.pir
==============================================================================
--- trunk/languages/lua/src/lib/luabasic.pir (original)
+++ trunk/languages/lua/src/lib/luabasic.pir Sat Nov 29 07:35:13 2008
@@ -257,8 +257,8 @@
if f == zero goto L2
L1:
f = getfunc(f, 1)
- $I0 = isa f, 'LuaClosure'
- if $I0 goto L3
+ $P0 = f.'get_outer'()
+ unless null $P0 goto L3
L2:
res = get_hll_global '_G'
.return (res)
@@ -272,8 +272,6 @@
if null f goto L1
$I0 = isa f, 'LuaFunction'
if $I0 goto L2
- $I0 = isa f, 'LuaClosure'
- if $I0 goto L2
L1:
.local int level
unless opt goto L3
@@ -713,8 +711,8 @@
.return ()
L1:
f = getfunc(f, 0)
- $I0 = isa f, 'LuaFunction'
- if $I0 goto L2
+ $P0 = f.'get_outer'()
+ if null $P0 goto L2
$I0 = lua_setfenv(f, table)
unless $I0 goto L2
.return (f)
@@ -922,13 +920,10 @@
_handler:
set status, 0
$I0 = isa err_, 'LuaFunction'
- if $I0 goto L1
- $I0 = isa err_, 'LuaClosure'
- unless $I0 goto L2
- L1:
+ unless $I0 goto L1
(res :slurpy) = err_()
.return (status, res :flat)
- L2:
+ L1:
.return (status)
.end
Modified: trunk/languages/lua/src/lib/luacoroutine.pir
==============================================================================
--- trunk/languages/lua/src/lib/luacoroutine.pir (original)
+++ trunk/languages/lua/src/lib/luacoroutine.pir Sat Nov 29 07:35:13 2008
@@ -70,8 +70,8 @@
.param pmc extra :slurpy
.local pmc res
lua_checktype(1, f, 'function')
- $I0 = isa f, 'LuaClosure'
- if $I0 goto L1
+ $P0 = f.'get_outer'()
+ unless null $P0 goto L1
lua_argerror(1, 'Lua function expected')
L1:
new res, 'LuaThread', f
Modified: trunk/languages/lua/src/lib/luapackage.pir
==============================================================================
--- trunk/languages/lua/src/lib/luapackage.pir (original)
+++ trunk/languages/lua/src/lib/luapackage.pir Sat Nov 29 07:35:13 2008
@@ -439,8 +439,6 @@
L4:
new $P1, 'LuaNil'
$P1 = $P0(modname) # call it
- $I0 = isa $P1 , 'LuaClosure'
- if $I0 goto L5
$I0 = isa $P1 , 'LuaFunction'
if $I0 goto L5
$I0 = isa $P1 , 'LuaString'
Modified: trunk/languages/lua/src/lib/luastring.pir
==============================================================================
--- trunk/languages/lua/src/lib/luastring.pir (original)
+++ trunk/languages/lua/src/lib/luastring.pir Sat Nov 29 07:35:13 2008
@@ -673,8 +673,6 @@
if $I0 goto L1
$I0 = isa repl, 'LuaString'
if $I0 goto L1
- $I0 = isa repl, 'LuaClosure'
- if $I0 goto L1
$I0 = isa repl, 'LuaFunction'
if $I0 goto L1
$I0 = isa repl, 'LuaTable'
@@ -729,12 +727,8 @@
unless $I0 goto L2
.tailcall add_s(b, s, match, repl)
L2:
- $I0 = isa repl, 'LuaClosure'
- if $I0 goto L3
$I0 = isa repl, 'LuaFunction'
- if $I0 goto L3
- goto L4
- L3:
+ unless $I0 goto L4
$P0 = captures(match, 1)
($P1) = repl($P0 :flat)
goto L5
Modified: trunk/languages/lua/src/pmc/lua.pmc
==============================================================================
--- trunk/languages/lua/src/pmc/lua.pmc (original)
+++ trunk/languages/lua/src/pmc/lua.pmc Sat Nov 29 07:35:13 2008
@@ -22,7 +22,6 @@
#include <locale.h>
INTVAL dynpmc_LuaBoolean;
-INTVAL dynpmc_LuaClosure;
INTVAL dynpmc_LuaFunction;
INTVAL dynpmc_LuaNil;
INTVAL dynpmc_LuaNumber;
@@ -65,8 +64,6 @@
if (pass) {
dynpmc_LuaBoolean = pmc_type(INTERP,
const_string(INTERP, "LuaBoolean"));
- dynpmc_LuaClosure = pmc_type(INTERP,
- const_string(INTERP, "LuaClosure"));
dynpmc_LuaFunction = pmc_type(INTERP,
const_string(INTERP, "LuaFunction"));
dynpmc_LuaNil = pmc_type(INTERP,
@@ -405,7 +402,7 @@
PMC *sub = sub_ctx->current_sub;
if (sub
&& PMC_metadata(sub)
- && VTABLE_isa(INTERP, sub, const_string(INTERP, "LuaClosure"))) {
+ && VTABLE_isa(INTERP, sub, const_string(INTERP, "LuaFunction"))) {
Parrot_Context_info info;
Parrot_block_GC_mark(INTERP);
Modified: trunk/languages/lua/src/pmc/lua_private.h
==============================================================================
--- trunk/languages/lua/src/pmc/lua_private.h (original)
+++ trunk/languages/lua/src/pmc/lua_private.h Sat Nov 29 07:35:13 2008
@@ -9,7 +9,6 @@
#include "parrot/parrot.h"
extern INTVAL dynpmc_LuaBoolean;
-extern INTVAL dynpmc_LuaClosure;
extern INTVAL dynpmc_LuaFunction;
extern INTVAL dynpmc_LuaNil;
extern INTVAL dynpmc_LuaNumber;
Modified: trunk/languages/lua/src/pmc/luaany.pmc
==============================================================================
--- trunk/languages/lua/src/pmc/luaany.pmc (original)
+++ trunk/languages/lua/src/pmc/luaany.pmc Sat Nov 29 07:35:13 2008
@@ -15,7 +15,6 @@
Class Parents
-----------------------------------------------
LuaBoolean LuaAny, Default
- LuaClosure Closure, LuaAny, Default
LuaFunction Sub, LuaAny, Default
LuaNil LuaAny, Default
LuaNumber LuaAny, Default
@@ -32,7 +31,6 @@
default value nil nil NULL
------------------------------------------------------------------
LuaBoolean nil - -
- LuaClosure nil yes -
LuaFunction nil yes -
LuaNil nil - -
LuaNumber nil - -
@@ -65,7 +63,7 @@
const_string(interp, "mt_string"));
}
- if (dynpmc_LuaClosure != type && dynpmc_LuaFunction != type) {
+ if (dynpmc_LuaFunction != type) {
if (obj->pmc_ext)
meta = PMC_metadata(obj);
@@ -160,8 +158,7 @@
PMC *meth = find_meth(INTERP, SELF, "__index");
if (meth) {
- if (dynpmc_LuaClosure == PMC_type(meth)
- || dynpmc_LuaFunction == PMC_type(meth)) {
+ if (dynpmc_LuaFunction == PMC_type(meth)) {
PMC *retval = Parrot_runops_fromc_args(INTERP, meth, "PPP",
SELF, key);
if (retval)
@@ -193,8 +190,7 @@
Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_ILL_INHERIT,
"attempt to index a %Ss value", SELF.name());
- if (dynpmc_LuaClosure == PMC_type(meth)
- || dynpmc_LuaFunction == PMC_type(meth)) {
+ if (dynpmc_LuaFunction == PMC_type(meth)) {
Parrot_runops_fromc_args(INTERP, meth, "vPPP",
SELF, key, value);
}
Modified: trunk/languages/lua/src/pmc/luafunction.pmc
==============================================================================
--- trunk/languages/lua/src/pmc/luafunction.pmc (original)
+++ trunk/languages/lua/src/pmc/luafunction.pmc Sat Nov 29 07:35:13 2008
@@ -10,10 +10,6 @@
C<LuaFunction> extends C<Parrot Sub> and C<LuaAny> to provide a class
with the behaviour of the Lua C<Function> type.
-C<LuaFunction> is used by standard libraries
-written in PIR.
-
-See also: F<languages/lua/pmc/luaclosure.pmc>
=head2 Overloaded Methods
@@ -39,6 +35,27 @@
/*
+=item C<void init_pmc(PMC *sub)>
+
+=cut
+
+*/
+ VTABLE void init_pmc(PMC *sub) {
+ if (VTABLE_isa(INTERP, sub, const_string(INTERP, "Sub"))) {
+ PMC_struct_val(SELF) = mem_allocate_zeroed_typed(Parrot_sub);
+ PMC_pmc_val(SELF) = NULL;
+ PMC_metadata(SELF) = NULL;
+ PObj_custom_mark_destroy_SETALL(SELF);
+ /* copy the sub struct */
+ memcpy(PMC_sub(SELF), PMC_sub(sub), sizeof (Parrot_sub));
+ }
+ else
+ Parrot_ex_throw_from_c_args(INTERP, NULL,
EXCEPTION_INVALID_OPERATION,
+ "not a Sub (%Ss)", SELF->vtable->whoami);
+ }
+
+/*
+
=item C<void mark()>
Marks the function as live.
Modified: trunk/languages/lua/src/pmc/luatable.pmc
==============================================================================
--- trunk/languages/lua/src/pmc/luatable.pmc (original)
+++ trunk/languages/lua/src/pmc/luatable.pmc Sat Nov 29 07:35:13 2008
@@ -509,8 +509,7 @@
else {
PMC *meth = find_meth(INTERP, SELF, "__index");
if (meth) {
- if (dynpmc_LuaClosure == PMC_type(meth)
- || dynpmc_LuaFunction == PMC_type(meth)) {
+ if (dynpmc_LuaFunction == PMC_type(meth)) {
value = Parrot_runops_fromc_args(INTERP, meth, "PPP",
SELF, key);
}
@@ -538,8 +537,7 @@
if (! lua_get(INTERP, PMC_hash(SELF), key)) {
PMC *meth = find_meth(INTERP, SELF, "__newindex");
if (meth) {
- if (dynpmc_LuaClosure == PMC_type(meth)
- || dynpmc_LuaFunction == PMC_type(meth)) {
+ if (dynpmc_LuaFunction == PMC_type(meth)) {
Parrot_runops_fromc_args(INTERP, meth, "vPPP", SELF,
key, value);
}
Modified: trunk/languages/lua/t/pmc/function.t
==============================================================================
--- trunk/languages/lua/t/pmc/function.t (original)
+++ trunk/languages/lua/t/pmc/function.t Sat Nov 29 07:35:13 2008
@@ -8,7 +8,7 @@
=head1 SYNOPSIS
- % perl -I../../lib t/pmc/function.t
+ % perl -I../lib lua/t/pmc/function.t
=head1 DESCRIPTION
@@ -20,7 +20,7 @@
use strict;
use warnings;
-use Parrot::Test tests => 11;
+use Parrot::Test tests => 20;
use Test::More;
pir_output_is( << 'CODE', << 'OUTPUT', 'check inheritance' );
@@ -173,6 +173,28 @@
f1()
OUTPUT
+pir_output_is( << 'CODE', << 'OUTPUT', 'check HLL' );
+.HLL 'Lua'
+.loadlib 'lua_group'
+.sub _main
+# .const 'LuaClosure' pmc1 = 'f1'
+ .const 'Sub' pmc1 = 'f1'
+ .local int bool1
+ bool1 = isa pmc1, 'LuaFunction'
+ print bool1
+ print "\n"
+ pmc1()
+ end
+.end
+.sub f1 :outer(_main)
+ print "f1()\n"
+ .return ()
+.end
+CODE
+1
+f1()
+OUTPUT
+
pir_output_is( << 'CODE', << 'OUTPUT', 'check HLL (autoboxing)' );
.HLL 'Lua'
.loadlib 'lua_group'
@@ -192,6 +214,25 @@
1
OUTPUT
+pir_output_is( << 'CODE', << 'OUTPUT', 'check HLL (autoboxing)' );
+.HLL 'Lua'
+.loadlib 'lua_group'
+.sub _main
+ .local pmc pmc1
+ pmc1 = test()
+ .local int bool1
+ bool1 = isa pmc1, 'LuaFunction'
+ print bool1
+ print "\n"
+.end
+.sub test :outer(_main)
+ .const 'Sub' T = 'test'
+ .return (T)
+.end
+CODE
+1
+OUTPUT
+
pir_output_like( << 'CODE', << 'OUTPUT', 'check tostring' );
.HLL 'Lua'
.loadlib 'lua_group'
@@ -233,6 +274,29 @@
nil
OUTPUT
+pir_output_is( << 'CODE', << 'OUTPUT', 'check init_pmc' );
+.HLL 'Lua'
+.loadlib 'lua_group'
+.sub _main
+ .const 'Sub' pmc1 = 'f1'
+ .local pmc pmc2
+ pmc2 = new 'LuaFunction', pmc1
+ .local int bool1
+ bool1 = isa pmc2, 'LuaFunction'
+ print bool1
+ print "\n"
+ pmc2()
+ end
+.end
+.sub f1 :outer(_main)
+ print "f1()\n"
+ .return ()
+.end
+CODE
+1
+f1()
+OUTPUT
+
pir_output_like( << 'CODE', << 'OUTPUT', 'load from pbc' );
.HLL 'Lua'
.loadlib 'lua_group'
@@ -255,6 +319,179 @@
/^function: [0-9A-Fa-f]{8}/
OUTPUT
+pir_output_like( << 'CODE', << 'OUTPUT', 'load from pbc' );
+.HLL 'Lua'
+.loadlib 'lua_group'
+.sub _main
+ load_bytecode 'languages/lua/lua.pbc'
+ lua_openlibs()
+ .local pmc tmp_0
+ tmp_0 = get_hll_global '_G'
+ .const 'LuaString' cst_1 = 'print'
+ .local pmc tmp_1
+ tmp_1 = tmp_0[cst_1]
+ tmp_1(tmp_1)
+.end
+CODE
+/^function: [0-9A-Fa-f]{8}/
+OUTPUT
+
+pir_output_like( << 'CODE', << 'OUTPUT', 'from pir' );
+.HLL 'Lua'
+.loadlib 'lua_group'
+.namespace [ 'basic' ]
+.sub _main
+ collectoff
+ luaopen_basic()
+ .local pmc tmp_0
+ tmp_0 = get_hll_global '_G'
+ .const 'LuaString' cst_1 = 'print'
+ .local pmc tmp_1
+ tmp_1 = tmp_0[cst_1]
+ tmp_1(tmp_1)
+.end
+.include 'languages/lua/src/lib/luaaux.pir'
+.include 'languages/lua/src/lib/luabasic.pir'
+CODE
+/^function: [0-9A-Fa-f]{8}/
+OUTPUT
+
+pir_output_like( << 'CODE', << 'OUTPUT', 'from compilation' );
+.HLL 'Lua'
+.loadlib 'lua_group'
+.sub _main
+ .local pmc comp
+ comp = compreg 'PIR'
+ $S0 = <<'PIRCODE'
+ .HLL 'Lua'
+ .loadlib 'lua_group'
+ .sub _loader
+ .local pmc table
+ table = new 'LuaTable'
+ .const 'Sub' F1 = 'f1'
+ newclosure $P0, F1
+ $P0.'setfenv'(table)
+ .return ($P0)
+ .end
+ .sub f1 :outer('_loader') :anon :lex
+ print "f1\n"
+ .end
+PIRCODE
+ $P0 = comp($S0)
+ $P1 = $P0[0] # _loader
+ $P2 = $P1() # f1
+ print $P2
+ print "\n"
+ $P3 = $P2.'getfenv'()
+ print $P3
+ print "\n"
+ $P2()
+.end
+CODE
+/^
+function:\s[0-9A-Fa-f]{8}\n
+table:\s[0-9A-Fa-f]{8}\n
+f1\n
+/x
+OUTPUT
+
+open my $X, '>', '../foo.pir';
+print {$X} q{
+ .HLL 'Lua'
+ .loadlib 'lua_group'
+ .sub _loader
+ .local pmc table
+ table = new 'LuaTable'
+ .const 'Sub' F1 = 'f1'
+ newclosure $P0, F1
+ $P0.'setfenv'(table)
+ .return ($P0)
+ .end
+ .sub f1 :outer('_loader') :anon :lex
+ print "f1\n"
+ .end
+};
+close $X;
+
+pir_output_like( << 'CODE', << 'OUTPUT', 'from PIR load_bytecode' );
+.HLL 'Lua'
+.loadlib 'lua_group'
+.sub _main
+ load_bytecode 'foo.pir'
+ $P0 = get_global '_loader'
+ $P2 = $P0() # f1
+ print $P2
+ print "\n"
+ $P3 = $P2.'getfenv'()
+ print $P3
+ print "\n"
+ $P2()
+.end
+CODE
+/^
+function:\s[0-9A-Fa-f]{8}\n
+table:\s[0-9A-Fa-f]{8}\n
+f1\n
+/x
+OUTPUT
+
+system("../parrot -o ../foo.pbc ../foo.pir");
+
+pir_output_like( << 'CODE', << 'OUTPUT', 'from PBC load_bytecode' );
+.HLL 'Lua'
+.loadlib 'lua_group'
+.sub _main
+ load_bytecode 'foo.pbc'
+ $P0 = get_global '_loader'
+ $P2 = $P0() # f1
+ print $P2
+ print "\n"
+ $P3 = $P2.'getfenv'()
+ print $P3
+ print "\n"
+ $P2()
+.end
+CODE
+/^
+function:\s[0-9A-Fa-f]{8}\n
+table:\s[0-9A-Fa-f]{8}\n
+f1\n
+/x
+OUTPUT
+
+unlink '../foo.pir';
+unlink '../foo.pbc';
+
+pir_output_like( << 'CODE', << 'OUTPUT', 'from compilation' );
+.HLL 'Lua'
+.loadlib 'lua_group'
+.sub _main
+ .local pmc comp
+ comp = compreg 'PIR'
+ $S0 = <<'PIRCODE'
+ .HLL 'Lua'
+ .loadlib 'lua_group'
+ .sub _loader
+ .end
+ .sub f1 :outer('_loader') :anon :lex
+ print "f1\n"
+ .end
+PIRCODE
+ $P0 = comp($S0)
+ $P2 = $P0[1] # _loader
+ print $P2
+ print "\n"
+ new $P3, 'LuaTable'
+ $P2.'setfenv'($P3)
+ $P2()
+.end
+CODE
+/^
+function:\s[0-9A-Fa-f]{8}\n
+f1\n
+/x
+OUTPUT
+
# Local Variables:
# mode: cperl
# cperl-indent-level: 4