=head1 DESCRIPTION
This test file describes an improvement for the directive .const
when an HLL is using.
In Lua, all types are implemented as PMC,
no Lua type is mapped with Parrot primitive type.
Lua PMC are derived from existing PMC, for example :
pmclass LuaNumber extends Float does float dynpmc group lua_group hll Lua
maps Float
pmclass LuaFunction extends Sub does sub dynpmc group lua_group hll Lua
maps Sub
But the directive .const seems to support only Parrot PMC.
In Lua, functions are "first class values".
So, it's important to instanciate and initialize them
with the PMC LuaFunction.
Is it a dream ?
Is it a future & planned feature ?
Or is it possible with an other syntax ?
(Lua supports closure & coroutine, it's allow to check their implementation
in Parrot with another language.)
François Perrad.
=cut
use strict;
use Parrot::Test tests => 3;
use Test::More;
pir_output_is(<<'CODE', <<'OUT', '.const with Parrot PMC' );
.sub foo :main
.const .Integer i = "12"
$S0 = typeof i
print $S0
print "\n"
print i
print "\n"
.const .Sub _test = "_test"
$S0 = typeof _test
print $S0
print "\n"
$P0 = _test
$P0()
print "ok\n"
.end
.sub _test
print "test\n"
.end
CODE
Integer
12
Sub
test
ok
OUT
TODO: {
local $TODO = "my expected behavior";
pir_output_is(<<'CODE', <<'OUT', '.const with Lua PMC' );
.HLL "Lua", "lua_group"
.sub foo :main
.const .LuaNumber n = "12.34"
$S0 = typeof n
print $S0
print "\n"
print n
print "\n"
.const .LuaFunction _test = "_test"
$S0 = typeof _test
print $S0
print "\n"
$P0 = _test
$P0()
print "ok\n"
.end
.sub _test
print "test\n"
.end
CODE
number
12.34
function
test
ok
OUT
}
pir_output_is(<<'CODE', <<'OUT', 'my current usage with Lua' );
.HLL "Lua", "lua_group"
.sub foo :main
new $P0, .LuaNumber
$P0 = 12.34
$S0 = typeof $P0
print $S0
print "\n"
print $P0
print "\n"
.const .Sub _test = "_test"
new $P0, .LuaFunction # useless
$P0 = _test
$S0 = typeof $P0
print $S0
print "\n"
$P0()
print "ok\n"
.end
.sub _test
print "test\n"
.end
CODE
number
12.34
Sub
test
ok
OUT