diff --git a/lua.pir b/lua.pir index 5458225..f616e9d 100644 --- a/lua.pir +++ b/lua.pir @@ -84,6 +84,8 @@ show version information. =cut +.loadlib 'io_ops' + .sub '__gcstop' :anon :init sweepoff # stop collector during initialization .end diff --git a/lua/POSTGrammar.tg b/lua/POSTGrammar.tg index bea5a9c..eb283b6 100644 --- a/lua/POSTGrammar.tg +++ b/lua/POSTGrammar.tg @@ -127,6 +127,7 @@ PIRCODE .tailcall $P0.'new'(start, 'node'=>node, 'prologue'=><<'PIRCODE') .include "interpinfo.pasm" .HLL "lua" +.loadlib "io_ops" .loadlib "lua_group" PIRCODE } diff --git a/lua/lib/luamath.pir b/lua/lib/luamath.pir index 3ff62ae..9ab18c0 100644 --- a/lua/lib/luamath.pir +++ b/lua/lib/luamath.pir @@ -47,6 +47,10 @@ L. .HLL 'lua' .loadlib 'lua_group' +.loadlib 'io_ops' +.loadlib 'sys_ops' +.loadlib 'math_ops' +.loadlib 'trans_ops' .namespace [ 'math' ] .sub 'luaopen_math' @@ -112,12 +116,6 @@ LIST set $P1, 'huge' _math[$P1] = $P0 - load_bytecode 'Math/Rand.pbc' - $P0 = get_root_namespace ['parrot'; 'Math'; 'Rand'] - $P1 = get_namespace - $P2 = split ' ', 'rand srand RAND_MAX' - $P0.'export_to'($P1, $P2) - .end @@ -410,8 +408,11 @@ LIST .local pmc res .local int u .local int l - $I0 = rand() - $I1 = RAND_MAX() + load_bytecode 'Math/Rand.pbc' + $P0 = get_root_global ['parrot'; 'Math'; 'Rand'], 'rand' + $I0 = $P0() + $P0 = get_root_global ['parrot'; 'Math'; 'Rand'], 'RAND_MAX' + $I1 = $P0() inc $I1 $N0 = $I0 / $I1 new res, 'LuaNumber' @@ -452,7 +453,9 @@ LIST .param pmc seed :optional .param pmc extra :slurpy $I1 = lua_checknumber(1, seed) - srand($I1) + load_bytecode 'Math/Rand.pbc' + $P0 = get_root_global ['parrot'; 'Math'; 'Rand'], 'srand' + $P0($I1) .end diff --git a/lua/lib/luaos.pir b/lua/lib/luaos.pir index 7f9b9e9..5274a1a 100644 --- a/lua/lib/luaos.pir +++ b/lua/lib/luaos.pir @@ -18,6 +18,8 @@ L. .HLL 'lua' .loadlib 'lua_group' +.loadlib 'io_ops' +.loadlib 'sys_ops' .namespace [ 'os' ] .sub 'luaopen_os' diff --git a/lua/lua51.pir b/lua/lua51.pir index d549a09..5ef297e 100644 --- a/lua/lua51.pir +++ b/lua/lua51.pir @@ -24,6 +24,8 @@ Used by F. =cut +.loadlib 'io_ops' + .namespace [ 'Lua' ] .sub '__onload' :anon :load diff --git a/luad.pir b/luad.pir index 53f2c58..7c0236c 100644 --- a/luad.pir +++ b/luad.pir @@ -17,6 +17,10 @@ L =cut +.loadlib 'io_ops' +.loadlib 'sys_ops' +.loadlib 'math_ops' +.loadlib 'trans_ops' .loadlib 'lua_group' .sub 'main' :main diff --git a/t/env.t b/t/env.t index d9aca35..5b00501 100755 --- a/t/env.t +++ b/t/env.t @@ -43,9 +43,10 @@ cmd .= " " cmd .= params L1: - $P0 = open cmd, 'rp' + $P0 = new 'FileHandle' + $P0.'open'(cmd, 'rp') $S0 = $P0.'readall'() - close $P0 + $P0.'close'() .return ($S0) .end diff --git a/t/lexico.t b/t/lexico.t index a0f732c..85da3c9 100755 --- a/t/lexico.t +++ b/t/lexico.t @@ -33,9 +33,10 @@ L. .sub 'lexico' :anon .param string code spew('lexico.lua', code) - $P0 = open 'parrot lua.pbc lexico.lua', 'rp' + $P0 = new 'FileHandle' + $P0.'open'('parrot lua.pbc lexico.lua', 'rp') $S0 = $P0.'readall'() - close $P0 + $P0.'close'() .return ($S0) .end diff --git a/t/luad.t b/t/luad.t index 3b8757e..d0fbf06 100755 --- a/t/luad.t +++ b/t/luad.t @@ -22,9 +22,10 @@ by Kein-Hong Man $P0 = loadlib 'os' .include 'test_more.pir' - $P0 = open 'luac -v', 'rp' - $S0 = readline $P0 - close $P0 + $P0 = new 'FileHandle' + $P0.'open'('luac -v', 'rp') + $S0 = $P0.'readline'() + $P0.'close'() $S0 = substr $S0, 0, 7 if $S0 == "Lua 5.1" goto L1 # skip_all("luac no available") @@ -104,9 +105,10 @@ by Kein-Hong Man .param string code spew('luad.lua', code) $I0 = spawnw 'luac -o luad.luac luad.lua' - $P0 = open 'parrot lua/luad.pbc luad.luac', 'rp' + $P0 = new 'FileHandle' + $P0.'open'('parrot lua/luad.pbc luad.luac', 'rp') $S0 = $P0.'readall'() - close $P0 + $P0.'close'() .return ($S0) .end diff --git a/t/shootout.t b/t/shootout.t index 35e1625..6fd48a9 100755 --- a/t/shootout.t +++ b/t/shootout.t @@ -58,9 +58,10 @@ See L. cmd .= " " cmd .= params L1: - $P0 = open cmd, 'rp' + $P0 = new 'FileHandle' + $P0.'open'(cmd, 'rp') $S0 = $P0.'readall'() - close $P0 + $P0.'close'() .return ($S0) .end diff --git a/t/test-from-lua.t b/t/test-from-lua.t index c916cdb..28aec49 100755 --- a/t/test-from-lua.t +++ b/t/test-from-lua.t @@ -55,9 +55,10 @@ Here is a one-line summary of each program: .param string filename .local string cmd cmd = "parrot lua.pbc " . filename - $P0 = open cmd, 'rp' + $P0 = new 'FileHandle' + $P0.'open'(cmd, 'rp') $S0 = $P0.'readall'() - close $P0 + $P0.'close'() .return ($S0) .end diff --git a/t/test_lex.t b/t/test_lex.t index dc74155..f8bd073 100755 --- a/t/test_lex.t +++ b/t/test_lex.t @@ -56,9 +56,10 @@ L. .sub 'lua_lex' :anon .param string code spew('test_lex.lua', code) - $P0 = open 'parrot test_lex.pir test_lex.lua', 'rp' + $P0 = new 'FileHandle' + $P0.'open'('parrot test_lex.pir test_lex.lua', 'rp') $S0 = $P0.'readall'() - close $P0 + $P0.'close'() .return ($S0) .end