Skip to content
This repository has been archived by the owner on Jun 9, 2018. It is now read-only.

Commit

Permalink
allows require of *.pbc compiled from .lua
Browse files Browse the repository at this point in the history
  • Loading branch information
fperrad committed Sep 19, 2009
1 parent 8c33dc2 commit ec38101
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 6 deletions.
5 changes: 3 additions & 2 deletions config/makefiles/root.in
Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions src/POSTGrammar.tg
Expand Up @@ -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')
Expand Down
2 changes: 1 addition & 1 deletion src/lib/luaaux.pir
Expand Up @@ -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)
Expand Down
4 changes: 3 additions & 1 deletion src/lib/luapackage.pir
Expand Up @@ -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')

Expand Down Expand Up @@ -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 '"
Expand Down
13 changes: 11 additions & 2 deletions src/lua51.pir
Expand Up @@ -103,7 +103,7 @@ used in F<languages/lua/src/PASTGrammar.tg>

=cut

.sub internal_error
.sub 'internal_error'
.param string msg
$S0 = "ERROR_INTERNAL (PAST): " . msg
$S0 .= "\n"
Expand All @@ -120,14 +120,23 @@ used in F<languages/lua/src/POSTGrammar.tg>

=cut

.sub internal_error
.sub 'internal_error'
.param string msg
$S0 = "ERROR_INTERNAL (POST): " . msg
$S0 .= "\n"
printerr $S0
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' ]

Expand Down
5 changes: 5 additions & 0 deletions src/yapp/Lua/pir.pm
Expand Up @@ -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;
}
Expand Down

0 comments on commit ec38101

Please sign in to comment.