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

Commit

Permalink
try to load .pbc before an existing .lua
Browse files Browse the repository at this point in the history
.pbc must be located in the same place than .lua
  • Loading branch information
fperrad committed Sep 21, 2009
1 parent 9ac0782 commit 497ce1b
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 36 deletions.
20 changes: 10 additions & 10 deletions config/makefiles/root.in
Expand Up @@ -115,7 +115,6 @@ BUILD_CLEANUPS := \
man \
"*.pbc" \
"lua/library/*.pbc" \
"lua/library/Test/*.pbc" \
"$(LIBPATH)/*.pbc" \
$(GEN_PIR) \
gl.lua \
Expand All @@ -136,7 +135,7 @@ TEST_CLEANUPS := \
"t/*.parrot_out"

build: build_core \
lua/library/Test/More.pbc \
Test/More.pbc \
lua/library/_helpers.pbc \
lua/library/alarm.pbc \
lua/library/base64.pbc \
Expand All @@ -163,6 +162,8 @@ build_core: \
$(LIB_PBCS) \
$(LIBPATH)/luaperl.pbc \
$(GEN_PBC) \
src/lua51_testlex_gen.pir \
src/dumplex_gen.pir \
src/yapp/Lua/parser.pm

all: build installable
Expand Down Expand Up @@ -243,13 +244,14 @@ $(LIBPATH)/luabytecode_gen.pir: $(LIBPATH)/luabytecode.rules src/build/translato
$(PERL) src/build/translator.pl $(LIBPATH)/luabytecode.rules \
--output $(LIBPATH)/luabytecode_gen.pir

$(LIBPATH)/More.pir: t/lua-TestMore/src/Test/More.lua
Test/More.pir: t/lua-TestMore/src/Test/More.lua
-$(MKPATH) Test
-$(CP) t/lua-TestMore/src/Test/More.lua Test/More.lua
-$(PARROT) luap.pir --target=pir Test/More.lua > $(LIBPATH)/More.pir
-$(PARROT) luap.pir --target=pir Test/More.lua > Test/More.pir

lua/library/Test/More.pbc: $(LIBPATH)/More.pir
-$(PARROT) --output=lua/library/Test/More.pbc $(LIBPATH)/More.pir
Test/More.pbc: Test/More.pir
-$(PARROT) --output=Test/More.pbc Test/More.pir
-$(CP) Test/More.pbc t/lua-TestMore/src/Test/More.pbc

lua/library/_helpers.pbc: $(LIBPATH)/_helpers.pir
$(PARROT) --output=lua/library/_helpers.pbc $(LIBPATH)/_helpers.pir
Expand Down Expand Up @@ -366,7 +368,7 @@ export LUA_INIT=platform = { osname=[[@osname@]], intsize=@intsize@, longsize=@l
spectest : build
#UNLESS(win32): which parrot-lua
cd t && cd lua-TestMore && cd test_lua51 \
&& prove --exec=parrot-lua *.t lib//*.t
&& prove -f --exec=parrot-lua --jobs 1 *.t lib//*.t

upload_pl = \
use strict; \
Expand Down Expand Up @@ -409,7 +411,7 @@ else { \
smoke : build
#UNLESS(win32): which parrot-lua
-cd t && cd lua-TestMore && cd test_lua51 \
&& prove --archive=test_lua51.tar.gz --exec=parrot-lua *.t
&& prove -f --archive=test_lua51.tar.gz --exec=parrot-lua --jobs 1 *.t
@perl -e '$(upload_pl)'

codetest: codetest-c codetest-make codetest-perl codetest-pir codetest-pod
Expand Down Expand Up @@ -482,8 +484,6 @@ install: installable
$(CP) lua/*.pbc $(LIB_DIR)/languages/lua
-$(MKPATH) $(LIB_DIR)/languages/lua/library
$(CP) lua/library/*.pbc $(LIB_DIR)/languages/lua/library
-$(MKPATH) $(LIB_DIR)/languages/lua/library/Test
$(CP) lua/library/Test/*.pbc $(LIB_DIR)/languages/lua/library/Test
-$(MKPATH) $(MANDIR)/man1
pod2man lua.pir > $(MANDIR)/man1/parrot-lua.1
pod2man luap.pir > $(MANDIR)/man1/parrot-luap.1
Expand Down
2 changes: 0 additions & 2 deletions lua/library/Test/.gitignore

This file was deleted.

48 changes: 48 additions & 0 deletions src/lib/luaaux.pir
Expand Up @@ -671,8 +671,12 @@ This function only loads the chunk; it does not run it.

=cut

.include 'stat.pasm'

.sub 'lua_loadfile'
.param string filename
.param string modname :optional
.param int has_modname :opt_flag
.local string chunkname
.local pmc f
unless filename == '' goto L1
Expand All @@ -681,6 +685,20 @@ This function only loads the chunk; it does not run it.
goto L2
L1:
chunkname = filename
unless has_modname goto L3
.local string pbcname
$I0 = index filename, '.lua'
pbcname = substr filename, 0, $I0
pbcname .= '.pbc'
$I0 = stat pbcname, .STAT_EXISTS
unless $I0 goto L3
load_bytecode pbcname
.local string funcname
funcname = mkfuncname(modname)
($P0, $S0) = loadfunc(pbcname, funcname)
if null $P0 goto L3
.return ($P0)
L3:
f = new 'FileHandle'
push_eh _handler
f.'open'(filename, 'r')
Expand Down Expand Up @@ -1142,6 +1160,27 @@ For development only.
L2:
.end

=item C<loadfunc (path, sym)>

=cut

.sub 'loadfunc'
.param string path
.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 '"
$S0 .= sym
$S0 .= "' in module '"
$S0 .= path
$S0 .= "'"
.return ($P0, $S0)
.end

=item C<mkarg (argv)>

Support variable number of arguments function call.
Expand All @@ -1153,6 +1192,15 @@ Support variable number of arguments function call.
.return (argv :flat)
.end

=item C<mkfuncname (modname)>

=cut

.sub 'mkfuncname'
.param string modname
$S0 = 'luaopen_' . modname
.return ($S0)
.end

=item C<not_implemented ()>

Expand Down
25 changes: 1 addition & 24 deletions src/lib/luapackage.pir
Expand Up @@ -229,7 +229,7 @@ LIST
# library not found in this path
.return ($P0)
L1:
($P0, $S0) = lua_loadfile(filename)
($P0, $S0) = lua_loadfile(filename, name)
unless null $P0 goto L2
loaderror($S1, filename, $S0)
L2:
Expand Down Expand Up @@ -281,29 +281,6 @@ LIST
.return ($P0)
.end

.sub 'mkfuncname' :anon
.param string modname
$S0 = 'luaopen_' . modname
.return ($S0)
.end

.sub 'loadfunc' :anon
.param string path
.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 '"
$S0 .= sym
$S0 .= "' in module '"
$S0 .= path
$S0 .= "'"
.return ($P0, $S0)
.end

.sub 'loader_preload' :anon
.param pmc name :optional
$S1 = lua_checkstring(1, name)
Expand Down

0 comments on commit 497ce1b

Please sign in to comment.