From ec38101479364d10c065dd5c8c9753d4a638c68b Mon Sep 17 00:00:00 2001 From: Francois Perrad Date: Sat, 19 Sep 2009 12:11:35 +0200 Subject: [PATCH] allows require of *.pbc compiled from .lua --- config/makefiles/root.in | 5 +++-- src/POSTGrammar.tg | 10 ++++++++++ src/lib/luaaux.pir | 2 +- src/lib/luapackage.pir | 4 +++- src/lua51.pir | 13 +++++++++++-- src/yapp/Lua/pir.pm | 5 +++++ 6 files changed, 33 insertions(+), 6 deletions(-) diff --git a/config/makefiles/root.in b/config/makefiles/root.in index 87f74b0..5519ca1 100644 --- a/config/makefiles/root.in +++ b/config/makefiles/root.in @@ -259,8 +259,9 @@ library/bitlib.pbc: $(LIBPATH)/bitlib.pir library/complex.pbc: $(LIBPATH)/complex.pir -$(PARROT) --output=library/complex.pbc $(LIBPATH)/complex.pir -#IF(has_opengl):$(LIBPATH)/gl.pir: $(LIBPATH)/gl.lua lua.pbc -#IF(has_opengl): -$(PARROT) luap.pir --target=pir $(LIBPATH)/gl.lua > $(LIBPATH)/gl.pir +#IF(has_opengl):$(LIBPATH)/gl.pir: $(LIBPATH)/gl.lua +#IF(has_opengl): -$(CP) $(LIBPATH)/gl.lua gl.lua +#IF(has_opengl): -$(PARROT) luap.pir --target=pir gl.lua > $(LIBPATH)/gl.pir #IF(has_opengl): #IF(has_opengl):library/gl.pbc: $(LIBPATH)/gl.pir #IF(has_opengl): -$(PARROT) --output=library/gl.pbc $(LIBPATH)/gl.pir diff --git a/src/POSTGrammar.tg b/src/POSTGrammar.tg index 629bc09..7766cb7 100644 --- a/src/POSTGrammar.tg +++ b/src/POSTGrammar.tg @@ -117,6 +117,16 @@ PIRCODE L3: PIRCODE post.'outer'(start) + .local pmc onload + $P0 = get_hll_global ['Lua'; 'POST'], 'Sub' + onload = $P0.'new'('name'=>'&on_require', 'pirflags'=>':anon :load') + $P0 = find_caller_lex '$?FILES' + $S1 = mkfuncname($P0) + onload.'push_pirop'('inline', $S0, $S1, 'inline'=><<'PIRCODE') + .const "Sub" entry = "%0" + set_hll_global "%1", entry +PIRCODE + start.'push'(onload) start.'push'(post) $P0 = get_hll_global ['Lua'; 'POST'], 'Chunk' .tailcall $P0.'new'(start, 'node'=>node, 'prologue'=><<'PIRCODE') diff --git a/src/lib/luaaux.pir b/src/lib/luaaux.pir index 5f9c1e1..c215633 100644 --- a/src/lib/luaaux.pir +++ b/src/lib/luaaux.pir @@ -608,7 +608,7 @@ messages and in debug information. lua_comp = compreg 'lua' push_eh _handler $P0 = lua_comp.'compile'(data) - $P0 = $P0[1] + $P0 = $P0[2] # 0=&start, 1=&on_require, 2=&main .local pmc env env = get_hll_global '_G' $P0.'setfenv'(env) diff --git a/src/lib/luapackage.pir b/src/lib/luapackage.pir index 8a4b3f3..2f0564e 100644 --- a/src/lib/luapackage.pir +++ b/src/lib/luapackage.pir @@ -64,7 +64,7 @@ LIST inc $P2 _loaders[$P2] = loader_PBCroot - setpath(_package, 'path', 'LUA_PATH', './?.lua;src/lib/?.lua') + setpath(_package, 'path', 'LUA_PATH', './?.lua') # setpath(_package, 'pbcpath', 'LUA_PBCPATH', 'library/?.pbc;./?.pbc;./?.pir') setpath(_package, 'pbcpath', 'LUA_PBCPATH', 'library/?.pbc;lua/?.pbc;./?.pbc;./?.pir') @@ -293,6 +293,8 @@ LIST .param string sym $P0 = get_hll_global sym if null $P0 goto L1 + $P1 = get_hll_global '_G' + $P0.'setfenv'($P1) .return ($P0) L1: $S0 = "can't found function '" diff --git a/src/lua51.pir b/src/lua51.pir index fb50805..e5e8e88 100644 --- a/src/lua51.pir +++ b/src/lua51.pir @@ -103,7 +103,7 @@ used in F =cut -.sub internal_error +.sub 'internal_error' .param string msg $S0 = "ERROR_INTERNAL (PAST): " . msg $S0 .= "\n" @@ -120,7 +120,7 @@ used in F =cut -.sub internal_error +.sub 'internal_error' .param string msg $S0 = "ERROR_INTERNAL (POST): " . msg $S0 .= "\n" @@ -128,6 +128,15 @@ used in F exit 1 .end +.sub 'mkfuncname' :anon + .param pmc file + $S1 = file + $I0 = index $S1, '.' + $S0 = substr $S1, 0, $I0 + $S0 = 'luaopen_' . $S0 + .return ($S0) +.end + .namespace [ 'POST';'Node' ] diff --git a/src/yapp/Lua/pir.pm b/src/yapp/Lua/pir.pm index 770e597..5e30b90 100644 --- a/src/yapp/Lua/pir.pm +++ b/src/yapp/Lua/pir.pm @@ -51,6 +51,11 @@ package pirVisitor; L1: .end +.sub '__on_require' :anon :load + .const 'Sub' entry = '_main' + set_hll_global 'luaopen_TODO_XXX', entry +.end + }; return $self; }