Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Works on OSX/Linux. Tweaked Michals build

  • Loading branch information...
commit 92d178a7e5e7d524823eb5738d36bfffdcb8bcb5 1 parent e9a0cca
@drahosp drahosp authored
View
55 CMakeLists.txt
@@ -1,5 +1,5 @@
# Copyright (C) 2011 LuaDist.
-# Submited by Michal Kottman
+# Submited by Michal Kottman, Peter Drahos
# Redistribution and use of this file is allowed according to the terms of the MIT license.
# For details see the COPYRIGHT file distributed with LuaDist.
# Please note that the package source code is licensed under its own license.
@@ -8,7 +8,6 @@ project ( metalua NONE )
cmake_minimum_required ( VERSION 2.8 )
include ( dist.cmake )
-find_package ( Lua51 REQUIRED )
find_program ( LUA NAMES lua lua.bat )
find_program ( LUAC NAMES luac luac.bat )
@@ -16,48 +15,30 @@ set ( SRC ${CMAKE_CURRENT_SOURCE_DIR}/src )
set ( BIN ${CMAKE_CURRENT_BINARY_DIR})
set ( LIB ${BIN}/lib )
-message ( STATUS "Preparing the metalua libraries" )
+file ( COPY ${SRC}/lib/ DESTINATION ${LIB} )
-file ( COPY ${SRC}/lib/ DESTINATION ${LIB} PATTERN ".in" EXCLUDE )
-configure_file ( ${SRC}/lib/metalua/package2.lua.in ${LIB}/metalua/package2.lua )
-configure_file ( ${SRC}/compiler/metalua.mlua.in ${LIB}/metalua.mlua )
-
-message ( STATUS "Compiling the parts of the compiler written in plain Lua" )
-
-execute_process (
- COMMAND ${LUAC} -o ${LIB}/metalua/bytecode.luac
- lopcodes.lua lcode.lua ldump.lua compile.lua
- COMMAND ${LUAC} -o ${LIB}/metalua/mlp.luac
- lexer.lua gg.lua mlp_lexer.lua mlp_misc.lua mlp_table.lua mlp_meta.lua mlp_expr.lua mlp_stat.lua mlp_ext.lua
- WORKING_DIRECTORY ${SRC}/compiler )
-
-message ( STATUS "Bootstrap the parts of the compiler written in metalua" )
-
-execute_process (
- COMMAND ${LUA} ${SRC}/build-utils/bootstrap.lua ${SRC}/compiler/mlc.mlua output=${LIB}/metalua/mlc.luac
- COMMAND ${LUA} ${SRC}/build-utils/bootstrap.lua ${LIB}/metalua.mlua output=${LIB}/metalua.luac
- WORKING_DIRECTORY ${LIB} )
-
-message ( STATUS "Finish the bootstrap: recompile the metalua parts of the compiler with itself" )
-
-execute_process (
- COMMAND ${LUA} ${LIB}/metalua.luac -vb -f ${SRC}/compiler/mlc.mlua -o ${LIB}/metalua/mlc.luac
- COMMAND ${LUA} ${LIB}/metalua.luac -vb -f ${LIB}/metalua.mlua -o ${LIB}/metalua.luac
- WORKING_DIRECTORY ${LIB} )
-
-message ( STATUS "Precompile metalua libraries" )
+add_custom_target ( bootstrap ALL
+ COMMAND ${LUAC} -o ${LIB}/metalua/bytecode.lua
+ ${SRC}/compiler/lopcodes.lua ${SRC}/compiler/lcode.lua ${SRC}/compiler/ldump.lua ${SRC}/compiler/compile.lua
+ COMMAND ${LUAC} -o ${LIB}/metalua/mlp.lua
+ ${SRC}/compiler/lexer.lua ${SRC}/compiler/gg.lua ${SRC}/compiler/mlp_lexer.lua ${SRC}/compiler/mlp_misc.lua ${SRC}/compiler/mlp_table.lua ${SRC}/compiler/mlp_meta.lua ${SRC}/compiler/mlp_expr.lua ${SRC}/compiler/mlp_stat.lua ${SRC}/compiler/mlp_ext.lua
+ COMMAND ${LUA} ${SRC}/build-utils/bootstrap.lua ${SRC}/compiler/mlc.mlua output=${LIB}/metalua/mlc.lua
+ COMMAND ${LUA} ${SRC}/build-utils/bootstrap.lua ${SRC}/compiler/metalua.mlua output=${LIB}/metalua.lua
+ COMMAND ${LUA} ${LIB}/metalua.lua -vb -f ${SRC}/compiler/mlc.mlua -o ${LIB}/metalua/mlc.lua
+ COMMAND ${LUA} ${LIB}/metalua.lua -vb -f ${SRC}/compiler/metalua.mlua -o ${LIB}/metalua.lua
+ WORKING_DIRECTORY ${LIB} VERBATIM)
file ( GLOB_RECURSE SRCS RELATIVE ${LIB} "${LIB}/*.mlua")
foreach ( S ${SRCS} )
get_filename_component ( P ${S} PATH )
get_filename_component ( D ${S} NAME_WE )
- message ( STATUS "Compiling ${S} to ${P}/${D}.luac" )
- execute_process (
- COMMAND ${LUA} ${LIB}/metalua.luac ${S} -o ${P}/${D}.luac
- WORKING_DIRECTORY ${LIB} )
-endforeach ( S )
+ add_custom_command ( OUTPUT ${P}/${D}.lua
+ COMMAND ${LUA} ${LIB}/metalua.lua ${S} -o ${P}/${D}.lua
+ WORKING_DIRECTORY ${LIB}
+ DEPENDS bootstrap )
+endforeach ()
-install_lua_executable ( metalua ${LIB}/metalua.luac )
+install_lua_executable ( metalua ${LIB}/metalua.lua )
install ( DIRECTORY ${LIB}/ DESTINATION ${INSTALL_LMOD} PATTERN "*.in" EXCLUDE)
install_doc ( doc/ )
install_foo ( junk/ )
View
3  src/compiler/metalua.mlua.in → src/compiler/metalua.mlua
@@ -1,7 +1,4 @@
--*-lua-*- Set as a metalua file because it requires some metalua libs
-
-package.path = './?.luac;'..(_PROGDIR or "") .. "/../@INSTALL_LMOD@/?.luac;"..package.path
-
--require 'verbose_require'
require 'metalua.compiler'
View
1  src/compiler/mlc.mlua
@@ -70,7 +70,6 @@ function mlc.convert (x, src_fmt, dst_fmt, name)
-- printf(" *** Convert a %s into a %s", src_fmt, dst_fmt)
-{ jump_to_point }
-
error "Can't perform this conversion (bad src name)"
POINT 'luafile', 'string' -- x is the src file's name
View
4 src/lib/metalua/mlc_xcall.lua
@@ -82,8 +82,8 @@ function mlc_xcall.client_file (luafile)
local tmpfilename = os.tmpname()
local cmd = string.format (
- [=[lua -l metalua.mlc_xcall -e "mlc_xcall.server([[%s]], [[%s]], %s)"]=],
- luafile, tmpfilename, mlc.metabugs and "true" or "false")
+ [=[%s -l metalua.mlc_xcall -e "mlc_xcall.server([[%s]], [[%s]], %s)"]=],
+ (_PROGDIR and _PROGDIR.."/lua" or "lua"), luafile, tmpfilename, mlc.metabugs and "true" or "false")
-- printf("os.execute [[%s]]\n\n", cmd)
View
9 src/lib/metalua/package2.lua.in → src/lib/metalua/package2.lua
@@ -4,10 +4,7 @@ require 'metalua.mlc'
package.metalua_extension_prefix = 'metalua.extension.'
-local dir = (_PROGDIR or "") .. "/@INSTALL_LMOD@"
-package.mpath = os.getenv 'LUA_MPATH' or
- './?.mlua;'..dir..'/?.mlua;'..dir..'/?/init.mlua'
-
+package.mpath = os.getenv 'LUA_MPATH' or string.gsub( package.path or "./?.mlua", "%.lua", "%.mlua")
----------------------------------------------------------------------
-- resc(k) returns "%"..k if it's a special regular expression char,
@@ -52,9 +49,9 @@ end
local function spring_load(filename)
-- FIXME: handle compilation errors
local pattern =
- [=[lua -l metalua.compiler -l serialize -e ]=]..
+ [=[%s -l metalua.compiler -l serialize -e ]=]..
[=["print(serialize(mlc.ast_of_luafile [[%s]]))"]=]
- local cmd = string.format (pattern, filename)
+ local cmd = string.format (pattern, (_PROGDIR and _PROGDIR.."/lua" or "lua"), filename)
--print ("running command: ``" .. cmd .. "''")
local fd = io.popen (cmd)
local ast_src = fd:read '*a'
Please sign in to comment.
Something went wrong with that request. Please try again.