├── .gitignore ├── .hgignore ├── AUTHORS ├── CMakeLists.txt ├── COPYRIGHT ├── ChangeLog ├── HISTORY ├── INSTALL ├── README ├── README.llvm-lua ├── TODO ├── cmake ├── CustomMacros.cmake └── FindLLVM.cmake ├── cmake_uninstall.cmake.in ├── doc ├── amazon.gif ├── contents.html ├── cover.png ├── logo.gif ├── lua.1 ├── lua.css ├── lua.html ├── luac.1 ├── luac.html ├── manual.css ├── manual.html └── readme.html ├── etc ├── README ├── all.c ├── embed_jit.c ├── embed_jit.cpp ├── lua.hpp ├── lua.ico ├── lua.pc ├── luavs.bat ├── min.c ├── noparser.c └── strict.lua ├── gen_changelog.sh ├── llvm-lua ├── CMakeLists.txt ├── COPYRIGHT.llvm-lua ├── LLVMCompiler.cpp ├── LLVMCompiler.h ├── LLVMDumper.cpp ├── LLVMDumper.h ├── TODO ├── bin2c.c ├── compile_all.sh ├── hook_parser.c ├── llvm-lua.cpp ├── llvm-luac.cpp ├── llvm_compiler.cpp ├── llvm_compiler.h ├── llvm_compiler_private.h ├── llvm_dumper.cpp ├── llvm_dumper.h ├── llvm_lmathlib.c ├── llvm_lua_config.h.in ├── load_embedded_bc.cpp ├── load_embedded_bc.h ├── load_jit_proto.c ├── load_jit_proto.h ├── load_liblua_main.cpp ├── load_liblua_main.h ├── load_vm_ops.cpp ├── load_vm_ops.h ├── lua-compiler.in ├── lua-cross-compiler.in ├── lua_compiler.c ├── lua_compiler.h ├── lua_core.c ├── lua_core.h ├── lua_interpreter.c ├── lua_interpreter.h ├── lua_main.c ├── lua_normal.c ├── lua_vm_ops.c ├── lua_vm_ops.h ├── lua_vm_ops_static.c ├── no_jit.c ├── run_tests.sh └── tests │ ├── NOTES │ ├── add.lua │ ├── arg_test.lua │ ├── big_table.lua │ ├── coroutine.lua │ ├── dump.lua │ ├── for.lua │ ├── hash2.lua │ ├── loadk.lua │ ├── local_nil.lua │ ├── loops.lua │ ├── lua_tail.lua │ ├── nestedloop.lua │ ├── nestedloop2.lua │ ├── nums.lua │ ├── scimark_loop.lua │ ├── scimark_rand.lua │ ├── stress_for.lua │ ├── test.lua │ ├── test2.lua │ ├── test3.lua │ ├── test4.lua │ ├── test_lineerror.lua │ ├── test_math.lua │ ├── test_tail.lua │ ├── test_tail_nil_multret.lua │ └── test_varg_tail2.lua ├── src ├── lapi.c ├── lapi.h ├── lauxlib.c ├── lauxlib.h ├── lbaselib.c ├── lcoco.c ├── lcoco.h ├── lcode.c ├── lcode.h ├── ldblib.c ├── ldebug.c ├── ldebug.h ├── ldo.c ├── ldo.h ├── ldump.c ├── lfunc.c ├── lfunc.h ├── lgc.c ├── lgc.h ├── linit.c ├── liolib.c ├── llex.c ├── llex.h ├── llimits.h ├── lmathlib.c ├── lmem.c ├── lmem.h ├── loadlib.c ├── lobject.c ├── lobject.h ├── lopcodes.c ├── lopcodes.h ├── loslib.c ├── lparser.c ├── lparser.h ├── lstate.c ├── lstate.h ├── lstring.c ├── lstring.h ├── lstrlib.c ├── ltable.c ├── ltable.h ├── ltablib.c ├── ltm.c ├── ltm.h ├── lua.c ├── lua.h ├── luac.c ├── luaconf.h ├── lualib.h ├── lundump.c ├── lundump.h ├── lvm.c ├── lvm.h ├── lzio.c ├── lzio.h └── print.c ├── test ├── README ├── bisect.lua ├── cf.lua ├── echo.lua ├── env.lua ├── factorial.lua ├── fib.lua ├── fibfor.lua ├── globals.lua ├── hello.lua ├── life.lua ├── luac.lua ├── printf.lua ├── readonly.lua ├── sieve.lua ├── sort.lua ├── table.lua ├── trace-calls.lua ├── trace-globals.lua └── xd.lua └── tools └── hg_import_split.lua /.gitignore: -------------------------------------------------------------------------------- 1 | build 2 | llvm-lua/*.bc 3 | llvm-lua/*_bc.h 4 | src/.libs 5 | src/*.o 6 | src/*.lo 7 | src/*.la 8 | src/*.a 9 | src/lua 10 | src/luac 11 | src/lua_test 12 | .*.swp 13 | -------------------------------------------------------------------------------- /.hgignore: -------------------------------------------------------------------------------- 1 | # Backup files 2 | .*~$ 3 | # Rejected patches 4 | .*\.orig$ 5 | .*\.rej$ 6 | # Build directory 7 | ^build$ 8 | -------------------------------------------------------------------------------- /AUTHORS: -------------------------------------------------------------------------------- 1 | bobby@neoawareness.com:Robert G. Jakabosky 2 | -------------------------------------------------------------------------------- /COPYRIGHT: -------------------------------------------------------------------------------- 1 | Lua License 2 | ----------- 3 | 4 | Lua is licensed under the terms of the MIT license reproduced below. 5 | This means that Lua is free software and can be used for both academic 6 | and commercial purposes at absolutely no cost. 7 | 8 | For details and rationale, see http://www.lua.org/license.html . 9 | 10 | =============================================================================== 11 | 12 | Copyright (C) 1994-2008 Lua.org, PUC-Rio. 13 | 14 | Permission is hereby granted, free of charge, to any person obtaining a copy 15 | of this software and associated documentation files (the "Software"), to deal 16 | in the Software without restriction, including without limitation the rights 17 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 18 | copies of the Software, and to permit persons to whom the Software is 19 | furnished to do so, subject to the following conditions: 20 | 21 | The above copyright notice and this permission notice shall be included in 22 | all copies or substantial portions of the Software. 23 | 24 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 25 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 26 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 27 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 28 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 29 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 30 | THE SOFTWARE. 31 | 32 | =============================================================================== 33 | 34 | (end of COPYRIGHT) 35 | -------------------------------------------------------------------------------- /INSTALL: -------------------------------------------------------------------------------- 1 | INSTALL for Lua 5.1 2 | 3 | * Building Lua 4 | ------------ 5 | Lua is built in the src directory, but the build process can be 6 | controlled from the top-level Makefile. 7 | 8 | Building Lua on Unix systems should be very easy. First do "make" and 9 | see if your platform is listed. If so, just do "make xxx", where xxx 10 | is your platform name. The platforms currently supported are: 11 | aix ansi bsd freebsd generic linux macosx mingw posix solaris 12 | 13 | If your platform is not listed, try the closest one or posix, generic, 14 | ansi, in this order. 15 | 16 | See below for customization instructions and for instructions on how 17 | to build with other Windows compilers. 18 | 19 | If you want to check that Lua has been built correctly, do "make test" 20 | after building Lua. Also, have a look at the example programs in test. 21 | 22 | * Installing Lua 23 | -------------- 24 | Once you have built Lua, you may want to install it in an official 25 | place in your system. In this case, do "make install". The official 26 | place and the way to install files are defined in Makefile. You must 27 | have the right permissions to install files. 28 | 29 | If you want to build and install Lua in one step, do "make xxx install", 30 | where xxx is your platform name. 31 | 32 | If you want to install Lua locally, then do "make local". This will 33 | create directories bin, include, lib, man, and install Lua there as 34 | follows: 35 | 36 | bin: lua luac 37 | include: lua.h luaconf.h lualib.h lauxlib.h lua.hpp 38 | lib: liblua.a 39 | man/man1: lua.1 luac.1 40 | 41 | These are the only directories you need for development. 42 | 43 | There are man pages for lua and luac, in both nroff and html, and a 44 | reference manual in html in doc, some sample code in test, and some 45 | useful stuff in etc. You don't need these directories for development. 46 | 47 | If you want to install Lua locally, but in some other directory, do 48 | "make install INSTALL_TOP=xxx", where xxx is your chosen directory. 49 | 50 | See below for instructions for Windows and other systems. 51 | 52 | * Customization 53 | ------------- 54 | Three things can be customized by editing a file: 55 | - Where and how to install Lua -- edit Makefile. 56 | - How to build Lua -- edit src/Makefile. 57 | - Lua features -- edit src/luaconf.h. 58 | 59 | You don't actually need to edit the Makefiles because you may set the 60 | relevant variables when invoking make. 61 | 62 | On the other hand, if you need to select some Lua features, you'll need 63 | to edit src/luaconf.h. The edited file will be the one installed, and 64 | it will be used by any Lua clients that you build, to ensure consistency. 65 | 66 | We strongly recommend that you enable dynamic loading. This is done 67 | automatically for all platforms listed above that have this feature 68 | (and also Windows). See src/luaconf.h and also src/Makefile. 69 | 70 | * Building Lua on Windows and other systems 71 | ----------------------------------------- 72 | If you're not using the usual Unix tools, then the instructions for 73 | building Lua depend on the compiler you use. You'll need to create 74 | projects (or whatever your compiler uses) for building the library, 75 | the interpreter, and the compiler, as follows: 76 | 77 | library: lapi.c lcode.c ldebug.c ldo.c ldump.c lfunc.c lgc.c llex.c 78 | lmem.c lobject.c lopcodes.c lparser.c lstate.c lstring.c 79 | ltable.c ltm.c lundump.c lvm.c lzio.c 80 | lauxlib.c lbaselib.c ldblib.c liolib.c lmathlib.c loslib.c 81 | ltablib.c lstrlib.c loadlib.c linit.c 82 | 83 | interpreter: library, lua.c 84 | 85 | compiler: library, luac.c print.c 86 | 87 | If you use Visual Studio .NET, you can use etc/luavs.bat in its 88 | "Command Prompt". 89 | 90 | If all you want is to build the Lua interpreter, you may put all .c files 91 | in a single project, except for luac.c and print.c. Or just use etc/all.c. 92 | 93 | To use Lua as a library in your own programs, you'll need to know how to 94 | create and use libraries with your compiler. 95 | 96 | As mentioned above, you may edit luaconf.h to select some features before 97 | building Lua. 98 | 99 | (end of INSTALL) 100 | -------------------------------------------------------------------------------- /README: -------------------------------------------------------------------------------- 1 | README for Lua 5.1 2 | 3 | See INSTALL for installation instructions. 4 | See HISTORY for a summary of changes since the last released version. 5 | 6 | * What is Lua? 7 | ------------ 8 | Lua is a powerful, light-weight programming language designed for extending 9 | applications. Lua is also frequently used as a general-purpose, stand-alone 10 | language. Lua is free software. 11 | 12 | For complete information, visit Lua's web site at http://www.lua.org/ . 13 | For an executive summary, see http://www.lua.org/about.html . 14 | 15 | Lua has been used in many different projects around the world. 16 | For a short list, see http://www.lua.org/uses.html . 17 | 18 | * Availability 19 | ------------ 20 | Lua is freely available for both academic and commercial purposes. 21 | See COPYRIGHT and http://www.lua.org/license.html for details. 22 | Lua can be downloaded at http://www.lua.org/download.html . 23 | 24 | * Installation 25 | ------------ 26 | Lua is implemented in pure ANSI C, and compiles unmodified in all known 27 | platforms that have an ANSI C compiler. In most Unix-like platforms, simply 28 | do "make" with a suitable target. See INSTALL for detailed instructions. 29 | 30 | * Origin 31 | ------ 32 | Lua is developed at Lua.org, a laboratory of the Department of Computer 33 | Science of PUC-Rio (the Pontifical Catholic University of Rio de Janeiro 34 | in Brazil). 35 | For more information about the authors, see http://www.lua.org/authors.html . 36 | 37 | (end of README) 38 | -------------------------------------------------------------------------------- /README.llvm-lua: -------------------------------------------------------------------------------- 1 | README for llvm-lua 2 | 3 | === Requires === 4 | * LLVM 2.8 5 | * Clang or llvm-gcc 4.2.x from llvm.org 6 | 7 | === Compile === 8 | * mkdir build 9 | * cd build 10 | for Release build: 11 | * cmake .. -DLLVM_PATH= -DCMAKE_BUILD_TYPE=Release 12 | for Debug build: 13 | * cmake .. -DLLVM_PATH= -DCMAKE_BUILD_TYPE=Debug 14 | * make 15 | 16 | === Install === 17 | * make install 18 | 19 | === Patches to lua/src === 20 | * Emergency Garbage Collector: http://lua-users.org/wiki/EmergencyGarbageCollector 21 | * LuaCoco-1.1.6: http://luajit.org/coco.html + (x86_64 support added) 22 | * a few hooks where added to support JIT compiled functions. 23 | 24 | === Programs === 25 | * llvm-lua: This command can be used to run Lua script. It uses the LLVM backend to JIT Lua scripts to machine code for faster execution. 26 | * llvm-luac: This command compiles Lua scripts into LLVM bitcode. 27 | * lua-compiler: This is a bash script that wraps llvm-luac to compile Lua scripts into standalone executables or loadable modules. 28 | 29 | === Libraries === 30 | -- Lua core without LLVM JIT support, but compatible with compiled modules. Can be used as drop-in replacements of the normal Lua libraries. 31 | * liblua_static.a & liblua.so 32 | 33 | -- Static library with LLVM JIT support requires static linking with LLVM libraries. 34 | * libllvm-lua_static.a & libllvm-lua.so 35 | 36 | -- Used for compling Lua scripts to standalone executables. 37 | * liblua_main.a 38 | 39 | === Using llvm-lua === 40 | The JIT/interpreter command 'llvm-lua' can be used just like the normal 'lua'. There are a lot of extra command line options that expose some options from LLVM, they are not required for normal use. The JIT will compile Lua code with optimization level 3 by default. 41 | 42 | === Static compiling Lua scripts === 43 | 'llvm-luac' alone can only compile Lua scripts to Lua bytecode or LLVM bitcode. A wrapper script called 'lua-compiler' is provided that wraps 'llvm-luac', the LLVM tools (llc & opt), and gcc. 44 | 45 | Compile standalone Lua script: 46 | lua-compiler script.lua 47 | outputs: ./script 48 | 49 | Compile Lua script as a module: 50 | lua-compiler -lua-module script.lua 51 | outputs: ./script.so 52 | 53 | === Embedding 'llvm-lua' with JIT support === 54 | The Lua C API is unchanged and no extra API functions are exposed by llvm-lua. The only change is how host app. is linked with the 'liblua-llvm.a' library instead of the normal 'liblua.a' library. 55 | 56 | Use the following command to link your C app with llvm-lua: 57 | gcc -o embed.o -c etc/embed_jit.c 58 | g++ -o embed embed.o -lllvm-lua `llvm-config --ldflags --libs core jit native linker` -rdynamic -Wl,-E -lm -ldl 59 | 60 | Use the following command to link your C++ app with llvm-lua: 61 | g++ -o embed.o -c etc/embed_jit.cpp 62 | g++ -o embed embed.o -lllvm-lua `llvm-config --ldflags --libs core jit native linker` -rdynamic -Wl,-E -lm -ldl 63 | 64 | -------------------------------------------------------------------------------- /TODO: -------------------------------------------------------------------------------- 1 | -- TODO list 2 | 3 | misc: 4 | * Port lua-compiler bash script to a Lua script. 5 | * handle coroutine c-stack alignment issues on x86_64 when compiling in DEBUG mode. 6 | * Add option to compile liblua_main.a without lua parser, lundump/ldump code. 7 | * Update to latest EGC patch. 8 | 9 | module naming issues: 10 | * change how the compiler names modules. 11 | * give the compiler a search path + module name "A.B.C" and have it compile A/B/C.lua into A/B/C.so 12 | * remove output file extension when nameing the module, instead of just the last three letters. 13 | 14 | lua-compiler script: 15 | * fix linking bug reported by DigitalKiwi: 16 | #CFLAGS=" -ggdb -O3 -fomit-frame-pointer -pipe -Wall " 17 | CFLAGS=" -O3 -fomit-frame-pointer -pipe -Wl,-E " 18 | http://www.tecgraf.puc-rio.br/~lhf/ftp/lua/install.html 19 | 20 | -------------------------------------------------------------------------------- /cmake/CustomMacros.cmake: -------------------------------------------------------------------------------- 1 | 2 | macro(add_llvm_bc_library _target) 3 | set(_llvm_cflags) 4 | get_property(_idirs DIRECTORY PROPERTY INCLUDE_DIRECTORIES) 5 | foreach(_idir ${_idirs}) 6 | set(_llvm_cflags ${_llvm_cflags} -I${_idir}) 7 | endforeach(_idir) 8 | 9 | if(${ARGC} GREATER 2) 10 | set(_bc_files) 11 | foreach(_file ${ARGN}) 12 | set(_bc_file "${CMAKE_CURRENT_BINARY_DIR}/${_file}.bc") 13 | set(_bc_files ${_bc_files} ${_bc_file}) 14 | add_custom_command(OUTPUT ${_bc_file} 15 | COMMAND ${LLVM_CC} ARGS ${BC_CFLAGS} ${_llvm_cflags} -o ${_bc_file} ${_file} 16 | WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} 17 | DEPENDS ${_file} 18 | ) 19 | endforeach(_file) 20 | add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${_target}.bc 21 | COMMAND ${LLVM_LD} ARGS -o ${CMAKE_CURRENT_BINARY_DIR}/${_target}.bc ${_bc_files} 22 | WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} 23 | DEPENDS ${_bc_files} 24 | ) 25 | else(${ARGC} GREATER 2) 26 | add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${_target}.bc 27 | COMMAND ${LLVM_CC} ARGS ${BC_CFLAGS} ${_llvm_cflags} -o ${CMAKE_CURRENT_BINARY_DIR}/${_target}.bc ${ARGV1} 28 | WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} 29 | DEPENDS ${ARGV1} 30 | ) 31 | endif(${ARGC} GREATER 2) 32 | endmacro(add_llvm_bc_library) 33 | 34 | macro(add_target_properties _target _name) 35 | set(_properties) 36 | foreach(_prop ${ARGN}) 37 | set(_properties "${_properties} ${_prop}") 38 | endforeach(_prop) 39 | get_target_property(_old_properties ${_target} ${_name}) 40 | if(NOT _old_properties) 41 | # in case it's NOTFOUND 42 | set(_old_properties) 43 | endif(NOT _old_properties) 44 | set_target_properties(${_target} PROPERTIES ${_name} "${_old_properties} ${_properties}") 45 | endmacro(add_target_properties) 46 | 47 | -------------------------------------------------------------------------------- /cmake/FindLLVM.cmake: -------------------------------------------------------------------------------- 1 | # - Find libev 2 | # Find the native LLVM includes and library 3 | # 4 | # LLVM_INCLUDE_DIR - where to find ev.h, etc. 5 | # LLVM_LIBRARIES - List of libraries when using libev. 6 | # LLVM_FOUND - True if libev found. 7 | 8 | find_program(LLVM_CONFIG_EXECUTABLE NAMES "${LLVM_PATH}/bin/llvm-config" DOC "llvm-config executable") 9 | 10 | execute_process( 11 | COMMAND ${LLVM_CONFIG_EXECUTABLE} --cppflags 12 | OUTPUT_VARIABLE LLVM_CFLAGS 13 | OUTPUT_STRIP_TRAILING_WHITESPACE 14 | ) 15 | 16 | execute_process( 17 | COMMAND ${LLVM_CONFIG_EXECUTABLE} --ldflags 18 | OUTPUT_VARIABLE LLVM_LFLAGS 19 | OUTPUT_STRIP_TRAILING_WHITESPACE 20 | ) 21 | execute_process( 22 | COMMAND ${LLVM_CONFIG_EXECUTABLE} --libs core jit native linker bitreader bitwriter ipo 23 | OUTPUT_VARIABLE LLVM_JIT_LIBS 24 | OUTPUT_STRIP_TRAILING_WHITESPACE 25 | ) 26 | execute_process( 27 | COMMAND ${LLVM_CONFIG_EXECUTABLE} --libs all 28 | OUTPUT_VARIABLE LLVM_ALL_LIBS 29 | OUTPUT_STRIP_TRAILING_WHITESPACE 30 | ) 31 | 32 | -------------------------------------------------------------------------------- /cmake_uninstall.cmake.in: -------------------------------------------------------------------------------- 1 | IF(NOT EXISTS "@CMAKE_BINARY_DIR@/install_manifest.txt") 2 | MESSAGE(FATAL_ERROR "Cannot find install manifest: \"@CMAKE_BINARY_DIR@/install_manifest.txt\"") 3 | ENDIF(NOT EXISTS "@CMAKE_BINARY_DIR@/install_manifest.txt") 4 | 5 | FILE(READ "@CMAKE_BINARY_DIR@/install_manifest.txt" files) 6 | STRING(REGEX REPLACE "\n" ";" files "${files}") 7 | FOREACH(file ${files}) 8 | MESSAGE(STATUS "Uninstalling \"$ENV{DESTDIR}${file}\"") 9 | EXEC_PROGRAM( 10 | "@CMAKE_COMMAND@" ARGS "-E remove \"$ENV{DESTDIR}${file}\"" 11 | OUTPUT_VARIABLE rm_out 12 | RETURN_VALUE rm_retval 13 | ) 14 | IF(NOT "${rm_retval}" STREQUAL 0) 15 | MESSAGE(FATAL_ERROR "Problem when removing \"$ENV{DESTDIR}${file}\"") 16 | ENDIF(NOT "${rm_retval}" STREQUAL 0) 17 | ENDFOREACH(file) 18 | 19 | -------------------------------------------------------------------------------- /doc/amazon.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Neopallium/llvm-lua/65123d2396296bf8a33c1253ac17b2bdb9b7e7ac/doc/amazon.gif -------------------------------------------------------------------------------- /doc/contents.html: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Neopallium/llvm-lua/65123d2396296bf8a33c1253ac17b2bdb9b7e7ac/doc/contents.html -------------------------------------------------------------------------------- /doc/cover.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Neopallium/llvm-lua/65123d2396296bf8a33c1253ac17b2bdb9b7e7ac/doc/cover.png -------------------------------------------------------------------------------- /doc/logo.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Neopallium/llvm-lua/65123d2396296bf8a33c1253ac17b2bdb9b7e7ac/doc/logo.gif -------------------------------------------------------------------------------- /doc/lua.1: -------------------------------------------------------------------------------- 1 | .\" $Id: lua.man,v 1.11 2006/01/06 16:03:34 lhf Exp $ 2 | .TH LUA 1 "$Date: 2006/01/06 16:03:34 $" 3 | .SH NAME 4 | lua \- Lua interpreter 5 | .SH SYNOPSIS 6 | .B lua 7 | [ 8 | .I options 9 | ] 10 | [ 11 | .I script 12 | [ 13 | .I args 14 | ] 15 | ] 16 | .SH DESCRIPTION 17 | .B lua 18 | is the stand-alone Lua interpreter. 19 | It loads and executes Lua programs, 20 | either in textual source form or 21 | in precompiled binary form. 22 | (Precompiled binaries are output by 23 | .BR luac , 24 | the Lua compiler.) 25 | .B lua 26 | can be used as a batch interpreter and also interactively. 27 | .LP 28 | The given 29 | .I options 30 | (see below) 31 | are executed and then 32 | the Lua program in file 33 | .I script 34 | is loaded and executed. 35 | The given 36 | .I args 37 | are available to 38 | .I script 39 | as strings in a global table named 40 | .BR arg . 41 | If these arguments contain spaces or other characters special to the shell, 42 | then they should be quoted 43 | (but note that the quotes will be removed by the shell). 44 | The arguments in 45 | .B arg 46 | start at 0, 47 | which contains the string 48 | .RI ' script '. 49 | The index of the last argument is stored in 50 | .BR arg.n . 51 | The arguments given in the command line before 52 | .IR script , 53 | including the name of the interpreter, 54 | are available in negative indices in 55 | .BR arg . 56 | .LP 57 | At the very start, 58 | before even handling the command line, 59 | .B lua 60 | executes the contents of the environment variable 61 | .BR LUA_INIT , 62 | if it is defined. 63 | If the value of 64 | .B LUA_INIT 65 | is of the form 66 | .RI '@ filename ', 67 | then 68 | .I filename 69 | is executed. 70 | Otherwise, the string is assumed to be a Lua statement and is executed. 71 | .LP 72 | Options start with 73 | .B '\-' 74 | and are described below. 75 | You can use 76 | .B "'\--'" 77 | to signal the end of options. 78 | .LP 79 | If no arguments are given, 80 | then 81 | .B "\-v \-i" 82 | is assumed when the standard input is a terminal; 83 | otherwise, 84 | .B "\-" 85 | is assumed. 86 | .LP 87 | In interactive mode, 88 | .B lua 89 | prompts the user, 90 | reads lines from the standard input, 91 | and executes them as they are read. 92 | If a line does not contain a complete statement, 93 | then a secondary prompt is displayed and 94 | lines are read until a complete statement is formed or 95 | a syntax error is found. 96 | So, one way to interrupt the reading of an incomplete statement is 97 | to force a syntax error: 98 | adding a 99 | .B ';' 100 | in the middle of a statement is a sure way of forcing a syntax error 101 | (except inside multiline strings and comments; these must be closed explicitly). 102 | If a line starts with 103 | .BR '=' , 104 | then 105 | .B lua 106 | displays the values of all the expressions in the remainder of the 107 | line. The expressions must be separated by commas. 108 | The primary prompt is the value of the global variable 109 | .BR _PROMPT , 110 | if this value is a string; 111 | otherwise, the default prompt is used. 112 | Similarly, the secondary prompt is the value of the global variable 113 | .BR _PROMPT2 . 114 | So, 115 | to change the prompts, 116 | set the corresponding variable to a string of your choice. 117 | You can do that after calling the interpreter 118 | or on the command line 119 | (but in this case you have to be careful with quotes 120 | if the prompt string contains a space; otherwise you may confuse the shell.) 121 | The default prompts are "> " and ">> ". 122 | .SH OPTIONS 123 | .TP 124 | .B \- 125 | load and execute the standard input as a file, 126 | that is, 127 | not interactively, 128 | even when the standard input is a terminal. 129 | .TP 130 | .BI \-e " stat" 131 | execute statement 132 | .IR stat . 133 | You need to quote 134 | .I stat 135 | if it contains spaces, quotes, 136 | or other characters special to the shell. 137 | .TP 138 | .B \-i 139 | enter interactive mode after 140 | .I script 141 | is executed. 142 | .TP 143 | .BI \-l " name" 144 | call 145 | .BI require(' name ') 146 | before executing 147 | .IR script . 148 | Typically used to load libraries. 149 | .TP 150 | .B \-v 151 | show version information. 152 | .SH "SEE ALSO" 153 | .BR luac (1) 154 | .br 155 | http://www.lua.org/ 156 | .SH DIAGNOSTICS 157 | Error messages should be self explanatory. 158 | .SH AUTHORS 159 | R. Ierusalimschy, 160 | L. H. de Figueiredo, 161 | and 162 | W. Celes 163 | .\" EOF 164 | -------------------------------------------------------------------------------- /doc/lua.css: -------------------------------------------------------------------------------- 1 | body { 2 | color: #000000 ; 3 | background-color: #FFFFFF ; 4 | font-family: sans-serif ; 5 | text-align: justify ; 6 | margin-right: 20px ; 7 | margin-left: 20px ; 8 | } 9 | 10 | h1, h2, h3, h4 { 11 | font-weight: normal ; 12 | font-style: italic ; 13 | } 14 | 15 | a:link { 16 | color: #000080 ; 17 | background-color: inherit ; 18 | text-decoration: none ; 19 | } 20 | 21 | a:visited { 22 | background-color: inherit ; 23 | text-decoration: none ; 24 | } 25 | 26 | a:link:hover, a:visited:hover { 27 | color: #000080 ; 28 | background-color: #E0E0FF ; 29 | } 30 | 31 | a:link:active, a:visited:active { 32 | color: #FF0000 ; 33 | } 34 | 35 | hr { 36 | border: 0 ; 37 | height: 1px ; 38 | color: #a0a0a0 ; 39 | background-color: #a0a0a0 ; 40 | } 41 | 42 | -------------------------------------------------------------------------------- /doc/lua.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | LUA man page 5 | 6 | 7 | 8 | 9 | 10 |

NAME

11 | lua - Lua interpreter 12 |

SYNOPSIS

13 | lua 14 | [ 15 | options 16 | ] 17 | [ 18 | script 19 | [ 20 | args 21 | ] 22 | ] 23 |

DESCRIPTION

24 | lua 25 | is the stand-alone Lua interpreter. 26 | It loads and executes Lua programs, 27 | either in textual source form or 28 | in precompiled binary form. 29 | (Precompiled binaries are output by 30 | luac, 31 | the Lua compiler.) 32 | lua 33 | can be used as a batch interpreter and also interactively. 34 |

35 | The given 36 | options 37 | (see below) 38 | are executed and then 39 | the Lua program in file 40 | script 41 | is loaded and executed. 42 | The given 43 | args 44 | are available to 45 | script 46 | as strings in a global table named 47 | arg. 48 | If these arguments contain spaces or other characters special to the shell, 49 | then they should be quoted 50 | (but note that the quotes will be removed by the shell). 51 | The arguments in 52 | arg 53 | start at 0, 54 | which contains the string 55 | 'script'. 56 | The index of the last argument is stored in 57 | arg.n. 58 | The arguments given in the command line before 59 | script, 60 | including the name of the interpreter, 61 | are available in negative indices in 62 | arg. 63 |

64 | At the very start, 65 | before even handling the command line, 66 | lua 67 | executes the contents of the environment variable 68 | LUA_INIT, 69 | if it is defined. 70 | If the value of 71 | LUA_INIT 72 | is of the form 73 | '@filename', 74 | then 75 | filename 76 | is executed. 77 | Otherwise, the string is assumed to be a Lua statement and is executed. 78 |

79 | Options start with 80 | '-' 81 | and are described below. 82 | You can use 83 | '--' 84 | to signal the end of options. 85 |

86 | If no arguments are given, 87 | then 88 | "-v -i" 89 | is assumed when the standard input is a terminal; 90 | otherwise, 91 | "-" 92 | is assumed. 93 |

94 | In interactive mode, 95 | lua 96 | prompts the user, 97 | reads lines from the standard input, 98 | and executes them as they are read. 99 | If a line does not contain a complete statement, 100 | then a secondary prompt is displayed and 101 | lines are read until a complete statement is formed or 102 | a syntax error is found. 103 | So, one way to interrupt the reading of an incomplete statement is 104 | to force a syntax error: 105 | adding a 106 | ';' 107 | in the middle of a statement is a sure way of forcing a syntax error 108 | (except inside multiline strings and comments; these must be closed explicitly). 109 | If a line starts with 110 | '=', 111 | then 112 | lua 113 | displays the values of all the expressions in the remainder of the 114 | line. The expressions must be separated by commas. 115 | The primary prompt is the value of the global variable 116 | _PROMPT, 117 | if this value is a string; 118 | otherwise, the default prompt is used. 119 | Similarly, the secondary prompt is the value of the global variable 120 | _PROMPT2. 121 | So, 122 | to change the prompts, 123 | set the corresponding variable to a string of your choice. 124 | You can do that after calling the interpreter 125 | or on the command line 126 | (but in this case you have to be careful with quotes 127 | if the prompt string contains a space; otherwise you may confuse the shell.) 128 | The default prompts are "> " and ">> ". 129 |

OPTIONS

130 |

131 | - 132 | load and execute the standard input as a file, 133 | that is, 134 | not interactively, 135 | even when the standard input is a terminal. 136 |

137 | -e stat 138 | execute statement 139 | stat. 140 | You need to quote 141 | stat 142 | if it contains spaces, quotes, 143 | or other characters special to the shell. 144 |

145 | -i 146 | enter interactive mode after 147 | script 148 | is executed. 149 |

150 | -l name 151 | call 152 | require('name') 153 | before executing 154 | script. 155 | Typically used to load libraries. 156 |

157 | -v 158 | show version information. 159 |

SEE ALSO

160 | luac(1) 161 |
162 | http://www.lua.org/ 163 |

DIAGNOSTICS

164 | Error messages should be self explanatory. 165 |

AUTHORS

166 | R. Ierusalimschy, 167 | L. H. de Figueiredo, 168 | and 169 | W. Celes 170 | 171 | 172 | 173 | -------------------------------------------------------------------------------- /doc/luac.1: -------------------------------------------------------------------------------- 1 | .\" $Id: luac.man,v 1.28 2006/01/06 16:03:34 lhf Exp $ 2 | .TH LUAC 1 "$Date: 2006/01/06 16:03:34 $" 3 | .SH NAME 4 | luac \- Lua compiler 5 | .SH SYNOPSIS 6 | .B luac 7 | [ 8 | .I options 9 | ] [ 10 | .I filenames 11 | ] 12 | .SH DESCRIPTION 13 | .B luac 14 | is the Lua compiler. 15 | It translates programs written in the Lua programming language 16 | into binary files that can be later loaded and executed. 17 | .LP 18 | The main advantages of precompiling chunks are: 19 | faster loading, 20 | protecting source code from accidental user changes, 21 | and 22 | off-line syntax checking. 23 | .LP 24 | Pre-compiling does not imply faster execution 25 | because in Lua chunks are always compiled into bytecodes before being executed. 26 | .B luac 27 | simply allows those bytecodes to be saved in a file for later execution. 28 | .LP 29 | Pre-compiled chunks are not necessarily smaller than the corresponding source. 30 | The main goal in pre-compiling is faster loading. 31 | .LP 32 | The binary files created by 33 | .B luac 34 | are portable only among architectures with the same word size and byte order. 35 | .LP 36 | .B luac 37 | produces a single output file containing the bytecodes 38 | for all source files given. 39 | By default, 40 | the output file is named 41 | .BR luac.out , 42 | but you can change this with the 43 | .B \-o 44 | option. 45 | .LP 46 | In the command line, 47 | you can mix 48 | text files containing Lua source and 49 | binary files containing precompiled chunks. 50 | This is useful to combine several precompiled chunks, 51 | even from different (but compatible) platforms, 52 | into a single precompiled chunk. 53 | .LP 54 | You can use 55 | .B "'\-'" 56 | to indicate the standard input as a source file 57 | and 58 | .B "'\--'" 59 | to signal the end of options 60 | (that is, 61 | all remaining arguments will be treated as files even if they start with 62 | .BR "'\-'" ). 63 | .LP 64 | The internal format of the binary files produced by 65 | .B luac 66 | is likely to change when a new version of Lua is released. 67 | So, 68 | save the source files of all Lua programs that you precompile. 69 | .LP 70 | .SH OPTIONS 71 | Options must be separate. 72 | .TP 73 | .B \-l 74 | produce a listing of the compiled bytecode for Lua's virtual machine. 75 | Listing bytecodes is useful to learn about Lua's virtual machine. 76 | If no files are given, then 77 | .B luac 78 | loads 79 | .B luac.out 80 | and lists its contents. 81 | .TP 82 | .BI \-o " file" 83 | output to 84 | .IR file , 85 | instead of the default 86 | .BR luac.out . 87 | (You can use 88 | .B "'\-'" 89 | for standard output, 90 | but not on platforms that open standard output in text mode.) 91 | The output file may be a source file because 92 | all files are loaded before the output file is written. 93 | Be careful not to overwrite precious files. 94 | .TP 95 | .B \-p 96 | load files but do not generate any output file. 97 | Used mainly for syntax checking and for testing precompiled chunks: 98 | corrupted files will probably generate errors when loaded. 99 | Lua always performs a thorough integrity test on precompiled chunks. 100 | Bytecode that passes this test is completely safe, 101 | in the sense that it will not break the interpreter. 102 | However, 103 | there is no guarantee that such code does anything sensible. 104 | (None can be given, because the halting problem is unsolvable.) 105 | If no files are given, then 106 | .B luac 107 | loads 108 | .B luac.out 109 | and tests its contents. 110 | No messages are displayed if the file passes the integrity test. 111 | .TP 112 | .B \-s 113 | strip debug information before writing the output file. 114 | This saves some space in very large chunks, 115 | but if errors occur when running a stripped chunk, 116 | then the error messages may not contain the full information they usually do. 117 | For instance, 118 | line numbers and names of local variables are lost. 119 | .TP 120 | .B \-v 121 | show version information. 122 | .SH FILES 123 | .TP 15 124 | .B luac.out 125 | default output file 126 | .SH "SEE ALSO" 127 | .BR lua (1) 128 | .br 129 | http://www.lua.org/ 130 | .SH DIAGNOSTICS 131 | Error messages should be self explanatory. 132 | .SH AUTHORS 133 | L. H. de Figueiredo, 134 | R. Ierusalimschy and 135 | W. Celes 136 | .\" EOF 137 | -------------------------------------------------------------------------------- /doc/luac.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | LUAC man page 5 | 6 | 7 | 8 | 9 | 10 |

NAME

11 | luac - Lua compiler 12 |

SYNOPSIS

13 | luac 14 | [ 15 | options 16 | ] [ 17 | filenames 18 | ] 19 |

DESCRIPTION

20 | luac 21 | is the Lua compiler. 22 | It translates programs written in the Lua programming language 23 | into binary files that can be later loaded and executed. 24 |

25 | The main advantages of precompiling chunks are: 26 | faster loading, 27 | protecting source code from accidental user changes, 28 | and 29 | off-line syntax checking. 30 |

31 | Precompiling does not imply faster execution 32 | because in Lua chunks are always compiled into bytecodes before being executed. 33 | luac 34 | simply allows those bytecodes to be saved in a file for later execution. 35 |

36 | Precompiled chunks are not necessarily smaller than the corresponding source. 37 | The main goal in precompiling is faster loading. 38 |

39 | The binary files created by 40 | luac 41 | are portable only among architectures with the same word size and byte order. 42 |

43 | luac 44 | produces a single output file containing the bytecodes 45 | for all source files given. 46 | By default, 47 | the output file is named 48 | luac.out, 49 | but you can change this with the 50 | -o 51 | option. 52 |

53 | In the command line, 54 | you can mix 55 | text files containing Lua source and 56 | binary files containing precompiled chunks. 57 | This is useful because several precompiled chunks, 58 | even from different (but compatible) platforms, 59 | can be combined into a single precompiled chunk. 60 |

61 | You can use 62 | '-' 63 | to indicate the standard input as a source file 64 | and 65 | '--' 66 | to signal the end of options 67 | (that is, 68 | all remaining arguments will be treated as files even if they start with 69 | '-'). 70 |

71 | The internal format of the binary files produced by 72 | luac 73 | is likely to change when a new version of Lua is released. 74 | So, 75 | save the source files of all Lua programs that you precompile. 76 |

77 |

OPTIONS

78 | Options must be separate. 79 |

80 | -l 81 | produce a listing of the compiled bytecode for Lua's virtual machine. 82 | Listing bytecodes is useful to learn about Lua's virtual machine. 83 | If no files are given, then 84 | luac 85 | loads 86 | luac.out 87 | and lists its contents. 88 |

89 | -o file 90 | output to 91 | file, 92 | instead of the default 93 | luac.out. 94 | (You can use 95 | '-' 96 | for standard output, 97 | but not on platforms that open standard output in text mode.) 98 | The output file may be a source file because 99 | all files are loaded before the output file is written. 100 | Be careful not to overwrite precious files. 101 |

102 | -p 103 | load files but do not generate any output file. 104 | Used mainly for syntax checking and for testing precompiled chunks: 105 | corrupted files will probably generate errors when loaded. 106 | Lua always performs a thorough integrity test on precompiled chunks. 107 | Bytecode that passes this test is completely safe, 108 | in the sense that it will not break the interpreter. 109 | However, 110 | there is no guarantee that such code does anything sensible. 111 | (None can be given, because the halting problem is unsolvable.) 112 | If no files are given, then 113 | luac 114 | loads 115 | luac.out 116 | and tests its contents. 117 | No messages are displayed if the file passes the integrity test. 118 |

119 | -s 120 | strip debug information before writing the output file. 121 | This saves some space in very large chunks, 122 | but if errors occur when running a stripped chunk, 123 | then the error messages may not contain the full information they usually do. 124 | For instance, 125 | line numbers and names of local variables are lost. 126 |

127 | -v 128 | show version information. 129 |

FILES

130 |

131 | luac.out 132 | default output file 133 |

SEE ALSO

134 | lua(1) 135 |
136 | http://www.lua.org/ 137 |

DIAGNOSTICS

138 | Error messages should be self explanatory. 139 |

AUTHORS

140 | L. H. de Figueiredo, 141 | R. Ierusalimschy and 142 | W. Celes 143 | 144 | 145 | 146 | -------------------------------------------------------------------------------- /doc/manual.css: -------------------------------------------------------------------------------- 1 | h3 code { 2 | font-family: inherit ; 3 | } 4 | 5 | pre { 6 | font-size: 105% ; 7 | } 8 | 9 | span.apii { 10 | float: right ; 11 | font-family: inherit ; 12 | } 13 | 14 | -------------------------------------------------------------------------------- /doc/readme.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | Lua documentation 4 | 5 | 6 | 7 | 8 | 9 |
10 |

11 | Lua 12 | Documentation 13 |

14 | 15 | This is the documentation included in the source distribution of Lua 5.1.4. 16 | 17 | 25 | 26 | Lua's 27 | official web site 28 | contains updated documentation, 29 | especially the 30 | reference manual. 31 |

32 | 33 |


34 | 35 | Last update: 36 | Tue Aug 12 14:46:07 BRT 2008 37 | 38 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /etc/README: -------------------------------------------------------------------------------- 1 | This directory contains some useful files and code. 2 | Unlike the code in ../src, everything here is in the public domain. 3 | 4 | If any of the makes fail, you're probably not using the same libraries 5 | used to build Lua. Set MYLIBS in Makefile accordingly. 6 | 7 | all.c 8 | Full Lua interpreter in a single file. 9 | Do "make one" for a demo. 10 | 11 | lua.hpp 12 | Lua header files for C++ using 'extern "C"'. 13 | 14 | lua.ico 15 | A Lua icon for Windows (and web sites: save as favicon.ico). 16 | Drawn by hand by Markus Gritsch . 17 | 18 | lua.pc 19 | pkg-config data for Lua 20 | 21 | luavs.bat 22 | Script to build Lua under "Visual Studio .NET Command Prompt". 23 | Run it from the toplevel as etc\luavs.bat. 24 | 25 | min.c 26 | A minimal Lua interpreter. 27 | Good for learning and for starting your own. 28 | Do "make min" for a demo. 29 | 30 | noparser.c 31 | Linking with noparser.o avoids loading the parsing modules in lualib.a. 32 | Do "make noparser" for a demo. 33 | 34 | strict.lua 35 | Traps uses of undeclared global variables. 36 | Do "make strict" for a demo. 37 | 38 | -------------------------------------------------------------------------------- /etc/all.c: -------------------------------------------------------------------------------- 1 | /* 2 | * all.c -- Lua core, libraries and interpreter in a single file 3 | */ 4 | 5 | #define luaall_c 6 | 7 | #include "lapi.c" 8 | #include "lcode.c" 9 | #include "ldebug.c" 10 | #include "ldo.c" 11 | #include "ldump.c" 12 | #include "lfunc.c" 13 | #include "lgc.c" 14 | #include "llex.c" 15 | #include "lmem.c" 16 | #include "lobject.c" 17 | #include "lopcodes.c" 18 | #include "lparser.c" 19 | #include "lstate.c" 20 | #include "lstring.c" 21 | #include "ltable.c" 22 | #include "ltm.c" 23 | #include "lundump.c" 24 | #include "lvm.c" 25 | #include "lzio.c" 26 | 27 | #include "lauxlib.c" 28 | #include "lbaselib.c" 29 | #include "ldblib.c" 30 | #include "liolib.c" 31 | #include "linit.c" 32 | #include "lmathlib.c" 33 | #include "loadlib.c" 34 | #include "loslib.c" 35 | #include "lstrlib.c" 36 | #include "ltablib.c" 37 | 38 | #include "lua.c" 39 | -------------------------------------------------------------------------------- /etc/embed_jit.c: -------------------------------------------------------------------------------- 1 | /* 2 | * min.c -- a minimal Lua interpreter 3 | * loads stdin only with minimal error handling. 4 | * no interaction, and no standard library, only a "print" function. 5 | */ 6 | 7 | #include 8 | 9 | #include "lua.h" 10 | #include "lauxlib.h" 11 | 12 | static int print(lua_State *L) 13 | { 14 | int n=lua_gettop(L); 15 | int i; 16 | for (i=1; i<=n; i++) 17 | { 18 | if (i>1) printf("\t"); 19 | if (lua_isstring(L,i)) 20 | printf("%s",lua_tostring(L,i)); 21 | else if (lua_isnil(L,i)) 22 | printf("%s","nil"); 23 | else if (lua_isboolean(L,i)) 24 | printf("%s",lua_toboolean(L,i) ? "true" : "false"); 25 | else 26 | printf("%s:%p",luaL_typename(L,i),lua_topointer(L,i)); 27 | } 28 | printf("\n"); 29 | return 0; 30 | } 31 | 32 | int main(int argc, char **argv) 33 | { 34 | lua_State *L=lua_open(); 35 | char *file=NULL; 36 | lua_register(L,"print",print); 37 | if (argc > 1) { 38 | file = argv[1]; 39 | } 40 | if (luaL_dofile(L,file)!=0) fprintf(stderr,"%s\n",lua_tostring(L,-1)); 41 | lua_close(L); 42 | return 0; 43 | } 44 | -------------------------------------------------------------------------------- /etc/embed_jit.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * min.c -- a minimal Lua interpreter 3 | * loads stdin only with minimal error handling. 4 | * no interaction, and no standard library, only a "print" function. 5 | */ 6 | 7 | #include 8 | 9 | extern "C" { 10 | #include "lua.h" 11 | #include "lauxlib.h" 12 | } 13 | 14 | static int print(lua_State *L) 15 | { 16 | int n=lua_gettop(L); 17 | int i; 18 | for (i=1; i<=n; i++) 19 | { 20 | if (i>1) printf("\t"); 21 | if (lua_isstring(L,i)) 22 | printf("%s",lua_tostring(L,i)); 23 | else if (lua_isnil(L,i)) 24 | printf("%s","nil"); 25 | else if (lua_isboolean(L,i)) 26 | printf("%s",lua_toboolean(L,i) ? "true" : "false"); 27 | else 28 | printf("%s:%p",luaL_typename(L,i),lua_topointer(L,i)); 29 | } 30 | printf("\n"); 31 | return 0; 32 | } 33 | 34 | int main(int argc, char **argv) 35 | { 36 | lua_State *L=lua_open(); 37 | char *file=NULL; 38 | lua_register(L,"print",print); 39 | if (argc > 1) { 40 | file = argv[1]; 41 | } 42 | if (luaL_dofile(L,file)!=0) fprintf(stderr,"%s\n",lua_tostring(L,-1)); 43 | lua_close(L); 44 | return 0; 45 | } 46 | -------------------------------------------------------------------------------- /etc/lua.hpp: -------------------------------------------------------------------------------- 1 | // lua.hpp 2 | // Lua header files for C++ 3 | // <> not supplied automatically because Lua also compiles as C++ 4 | 5 | extern "C" { 6 | #include "lua.h" 7 | #include "lualib.h" 8 | #include "lauxlib.h" 9 | } 10 | -------------------------------------------------------------------------------- /etc/lua.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Neopallium/llvm-lua/65123d2396296bf8a33c1253ac17b2bdb9b7e7ac/etc/lua.ico -------------------------------------------------------------------------------- /etc/lua.pc: -------------------------------------------------------------------------------- 1 | # lua.pc -- pkg-config data for Lua 2 | 3 | # vars from install Makefile 4 | 5 | # grep '^V=' ../Makefile 6 | V= 5.1 7 | # grep '^R=' ../Makefile 8 | R= 5.1.4 9 | 10 | # grep '^INSTALL_.*=' ../Makefile | sed 's/INSTALL_TOP/prefix/' 11 | prefix= /usr 12 | INSTALL_BIN= ${prefix}/bin 13 | INSTALL_INC= ${prefix}/include 14 | INSTALL_LIB= ${prefix}/lib 15 | INSTALL_MAN= ${prefix}/man/man1 16 | INSTALL_LMOD= ${prefix}/share/lua/${V} 17 | INSTALL_CMOD= ${prefix}/lib/lua/${V} 18 | 19 | # canonical vars 20 | exec_prefix=${prefix} 21 | libdir=${exec_prefix}/lib 22 | includedir=${prefix}/include 23 | 24 | Name: LLVM-Lua 25 | Description: An Extensible Extension Language with JIT support from LLVM 26 | Version: ${R} 27 | Requires: 28 | Libs: -L${libdir} -llua -lm `llvm-config --ldflags --libs core jit native bitreader bitwriter ipo` 29 | Cflags: -I${includedir} 30 | 31 | # (end of lua.pc) 32 | -------------------------------------------------------------------------------- /etc/luavs.bat: -------------------------------------------------------------------------------- 1 | @rem Script to build Lua under "Visual Studio .NET Command Prompt". 2 | @rem Do not run from this directory; run it from the toplevel: etc\luavs.bat . 3 | @rem It creates lua51.dll, lua51.lib, lua.exe, and luac.exe in src. 4 | @rem (contributed by David Manura and Mike Pall) 5 | 6 | @setlocal 7 | @set MYCOMPILE=cl /nologo /MD /O2 /W3 /c /D_CRT_SECURE_NO_DEPRECATE 8 | @set MYLINK=link /nologo 9 | @set MYMT=mt /nologo 10 | 11 | cd src 12 | %MYCOMPILE% /DLUA_BUILD_AS_DLL l*.c 13 | del lua.obj luac.obj 14 | %MYLINK% /DLL /out:lua51.dll l*.obj 15 | if exist lua51.dll.manifest^ 16 | %MYMT% -manifest lua51.dll.manifest -outputresource:lua51.dll;2 17 | %MYCOMPILE% /DLUA_BUILD_AS_DLL lua.c 18 | %MYLINK% /out:lua.exe lua.obj lua51.lib 19 | if exist lua.exe.manifest^ 20 | %MYMT% -manifest lua.exe.manifest -outputresource:lua.exe 21 | %MYCOMPILE% l*.c print.c 22 | del lua.obj linit.obj lbaselib.obj ldblib.obj liolib.obj lmathlib.obj^ 23 | loslib.obj ltablib.obj lstrlib.obj loadlib.obj 24 | %MYLINK% /out:luac.exe *.obj 25 | if exist luac.exe.manifest^ 26 | %MYMT% -manifest luac.exe.manifest -outputresource:luac.exe 27 | del *.obj *.manifest 28 | cd .. 29 | -------------------------------------------------------------------------------- /etc/min.c: -------------------------------------------------------------------------------- 1 | /* 2 | * min.c -- a minimal Lua interpreter 3 | * loads stdin only with minimal error handling. 4 | * no interaction, and no standard library, only a "print" function. 5 | */ 6 | 7 | #include 8 | 9 | #include "lua.h" 10 | #include "lauxlib.h" 11 | 12 | static int print(lua_State *L) 13 | { 14 | int n=lua_gettop(L); 15 | int i; 16 | for (i=1; i<=n; i++) 17 | { 18 | if (i>1) printf("\t"); 19 | if (lua_isstring(L,i)) 20 | printf("%s",lua_tostring(L,i)); 21 | else if (lua_isnil(L,i)) 22 | printf("%s","nil"); 23 | else if (lua_isboolean(L,i)) 24 | printf("%s",lua_toboolean(L,i) ? "true" : "false"); 25 | else 26 | printf("%s:%p",luaL_typename(L,i),lua_topointer(L,i)); 27 | } 28 | printf("\n"); 29 | return 0; 30 | } 31 | 32 | int main(void) 33 | { 34 | lua_State *L=lua_open(); 35 | lua_register(L,"print",print); 36 | if (luaL_dofile(L,NULL)!=0) fprintf(stderr,"%s\n",lua_tostring(L,-1)); 37 | lua_close(L); 38 | return 0; 39 | } 40 | -------------------------------------------------------------------------------- /etc/noparser.c: -------------------------------------------------------------------------------- 1 | /* 2 | * The code below can be used to make a Lua core that does not contain the 3 | * parsing modules (lcode, llex, lparser), which represent 35% of the total core. 4 | * You'll only be able to load binary files and strings, precompiled with luac. 5 | * (Of course, you'll have to build luac with the original parsing modules!) 6 | * 7 | * To use this module, simply compile it ("make noparser" does that) and list 8 | * its object file before the Lua libraries. The linker should then not load 9 | * the parsing modules. To try it, do "make luab". 10 | * 11 | * If you also want to avoid the dump module (ldump.o), define NODUMP. 12 | * #define NODUMP 13 | */ 14 | 15 | #define LUA_CORE 16 | 17 | #include "llex.h" 18 | #include "lparser.h" 19 | #include "lzio.h" 20 | 21 | LUAI_FUNC void luaX_init (lua_State *L) { 22 | UNUSED(L); 23 | } 24 | 25 | LUAI_FUNC Proto *luaY_parser (lua_State *L, ZIO *z, Mbuffer *buff, const char *name) { 26 | UNUSED(z); 27 | UNUSED(buff); 28 | UNUSED(name); 29 | lua_pushliteral(L,"parser not loaded"); 30 | lua_error(L); 31 | return NULL; 32 | } 33 | 34 | #ifdef NODUMP 35 | #include "lundump.h" 36 | 37 | LUAI_FUNC int luaU_dump (lua_State* L, const Proto* f, lua_Writer w, void* data, int strip) { 38 | UNUSED(f); 39 | UNUSED(w); 40 | UNUSED(data); 41 | UNUSED(strip); 42 | #if 1 43 | UNUSED(L); 44 | return 0; 45 | #else 46 | lua_pushliteral(L,"dumper not loaded"); 47 | lua_error(L); 48 | #endif 49 | } 50 | #endif 51 | -------------------------------------------------------------------------------- /etc/strict.lua: -------------------------------------------------------------------------------- 1 | -- 2 | -- strict.lua 3 | -- checks uses of undeclared global variables 4 | -- All global variables must be 'declared' through a regular assignment 5 | -- (even assigning nil will do) in a main chunk before being used 6 | -- anywhere or assigned to inside a function. 7 | -- 8 | 9 | local getinfo, error, rawset, rawget = debug.getinfo, error, rawset, rawget 10 | 11 | local mt = getmetatable(_G) 12 | if mt == nil then 13 | mt = {} 14 | setmetatable(_G, mt) 15 | end 16 | 17 | mt.__declared = {} 18 | 19 | local function what () 20 | local d = getinfo(3, "S") 21 | return d and d.what or "C" 22 | end 23 | 24 | mt.__newindex = function (t, n, v) 25 | if not mt.__declared[n] then 26 | local w = what() 27 | if w ~= "main" and w ~= "C" then 28 | error("assign to undeclared variable '"..n.."'", 2) 29 | end 30 | mt.__declared[n] = true 31 | end 32 | rawset(t, n, v) 33 | end 34 | 35 | mt.__index = function (t, n) 36 | if not mt.__declared[n] and what() ~= "C" then 37 | error("variable '"..n.."' is not declared", 2) 38 | end 39 | return rawget(t, n) 40 | end 41 | 42 | -------------------------------------------------------------------------------- /gen_changelog.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | 4 | svn2cl --authors=AUTHORS --break-before-msg --group-by-day -o ChangeLog 5 | 6 | -------------------------------------------------------------------------------- /llvm-lua/COPYRIGHT.llvm-lua: -------------------------------------------------------------------------------- 1 | Copyright (c) 2008 Robert G. Jakabosky 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in 11 | all copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | THE SOFTWARE. 20 | 21 | MIT License: http://www.opensource.org/licenses/mit-license.php 22 | 23 | -------------------------------------------------------------------------------- /llvm-lua/LLVMCompiler.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2009 Robert G. Jakabosky 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy 5 | of this software and associated documentation files (the "Software"), to deal 6 | in the Software without restriction, including without limitation the rights 7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | copies of the Software, and to permit persons to whom the Software is 9 | furnished to do so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in 12 | all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | THE SOFTWARE. 21 | 22 | MIT License: http://www.opensource.org/licenses/mit-license.php 23 | */ 24 | 25 | #ifndef LLVMCOMPILER_h 26 | #define LLVMCOMPILER_h 27 | 28 | #include "llvm/Support/IRBuilder.h" 29 | #include "llvm/Module.h" 30 | #include "llvm/LLVMContext.h" 31 | 32 | #include "lua_core.h" 33 | 34 | #ifdef __cplusplus 35 | extern "C" { 36 | #endif 37 | 38 | #include "lobject.h" 39 | 40 | #include "lua_vm_ops.h" 41 | 42 | #ifdef __cplusplus 43 | } 44 | #endif 45 | 46 | namespace llvm { 47 | class FunctionPassManager; 48 | class ExecutionEngine; 49 | class Timer; 50 | } 51 | 52 | class LLVMCompiler { 53 | private: 54 | class OPFunc { 55 | public: 56 | const vm_func_info *info; 57 | bool compiled; 58 | llvm::Function *func; 59 | OPFunc *next; 60 | 61 | OPFunc(const vm_func_info *info_, OPFunc *next_) : 62 | info(info_), compiled(false), func(NULL), next(next_) {} 63 | ~OPFunc() { 64 | if(next) delete next; 65 | } 66 | }; 67 | class OPValues { 68 | private: 69 | int len; 70 | llvm::Value **values; 71 | 72 | public: 73 | OPValues(int len_) : len(len_), values(new llvm::Value *[len_]) { 74 | for(int i = 0; i < len; ++i) { 75 | values[i] = NULL; 76 | } 77 | } 78 | 79 | ~OPValues() { 80 | delete[] values; 81 | } 82 | void set(int idx, llvm::Value *val) { 83 | assert(idx >= 0 && idx < len); 84 | values[idx] = val; 85 | } 86 | llvm::Value *get(int idx) { 87 | assert(idx >= 0 && idx < len); 88 | return values[idx]; 89 | } 90 | }; 91 | 92 | private: 93 | llvm::LLVMContext Context; 94 | llvm::Module *M; 95 | llvm::FunctionPassManager *TheFPM; 96 | llvm::ExecutionEngine *TheExecutionEngine; 97 | bool strip_code; 98 | 99 | // struct types. 100 | llvm::Type *Ty_TValue; 101 | llvm::Type *Ty_TValue_ptr; 102 | llvm::Type *Ty_LClosure; 103 | llvm::Type *Ty_LClosure_ptr; 104 | llvm::Type *Ty_lua_State; 105 | llvm::Type *Ty_lua_State_ptr; 106 | // common function types. 107 | llvm::FunctionType *lua_func_type; 108 | // functions to get LClosure & constants pointer. 109 | llvm::Function *vm_get_current_closure; 110 | llvm::Function *vm_get_current_constants; 111 | llvm::Function *vm_get_number; 112 | llvm::Function *vm_get_long; 113 | llvm::Function *vm_set_number; 114 | llvm::Function *vm_set_long; 115 | // function for counting each executed op. 116 | llvm::Function *vm_count_OP; 117 | // function for print each executed op. 118 | llvm::Function *vm_print_OP; 119 | // function for handling count/line debug hooks. 120 | llvm::Function *vm_next_OP; 121 | // function for handling a block of simple opcodes. 122 | llvm::Function *vm_mini_vm; 123 | // available op function for each opcode. 124 | OPFunc **vm_op_funcs; 125 | // count compiled opcodes. 126 | int *opcode_stats; 127 | 128 | // timers 129 | llvm::Timer *lua_to_llvm; 130 | llvm::Timer *codegen; 131 | 132 | // opcode hints/values/blocks/need_block arrays used in compile() method. 133 | int opcode_data_len; // length of opcode arrays. 134 | hint_t *op_hints; 135 | OPValues **op_values; 136 | llvm::BasicBlock **op_blocks; 137 | bool *need_op_block; 138 | // resize the opcode hint data arrays. 139 | void resize_opcode_data(int code_len); 140 | // reset/clear the opcode hint data arrays. 141 | void clear_opcode_data(int code_len); 142 | 143 | public: 144 | LLVMCompiler(int useJIT); 145 | ~LLVMCompiler(); 146 | 147 | /* 148 | * set code stripping mode. 149 | */ 150 | void setStripCode(bool strip) { 151 | strip_code = strip; 152 | } 153 | 154 | /* 155 | * return the module. 156 | */ 157 | llvm::Module *getModule() { 158 | return M; 159 | } 160 | 161 | llvm::LLVMContext& getCtx() { 162 | return Context; 163 | } 164 | 165 | llvm::FunctionType *get_lua_func_type() { 166 | return lua_func_type; 167 | } 168 | 169 | llvm::Type *get_var_type(val_t type, hint_t hints); 170 | 171 | llvm::Value *get_proto_constant(TValue *constant); 172 | 173 | /* 174 | * Pre-Compile all loaded functions. 175 | */ 176 | void compileAll(lua_State *L, Proto *parent); 177 | 178 | void compile(lua_State *L, Proto *p); 179 | 180 | void free(lua_State *L, Proto *p); 181 | }; 182 | 183 | #endif 184 | 185 | -------------------------------------------------------------------------------- /llvm-lua/LLVMDumper.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2009 Robert G. Jakabosky 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy 5 | of this software and associated documentation files (the "Software"), to deal 6 | in the Software without restriction, including without limitation the rights 7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | copies of the Software, and to permit persons to whom the Software is 9 | furnished to do so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in 12 | all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | THE SOFTWARE. 21 | 22 | MIT License: http://www.opensource.org/licenses/mit-license.php 23 | */ 24 | 25 | #ifndef LLVMDUMPER_h 26 | #define LLVMDUMPER_h 27 | 28 | #include "llvm/Module.h" 29 | #include "lua_core.h" 30 | 31 | #ifdef __cplusplus 32 | extern "C" { 33 | #endif 34 | 35 | #include "lobject.h" 36 | 37 | #ifdef __cplusplus 38 | } 39 | #endif 40 | 41 | namespace llvm { 42 | class Module; 43 | class Type; 44 | class StructType; 45 | class FunctionType; 46 | class Constant; 47 | class GlobalVariable; 48 | } 49 | 50 | class LLVMCompiler; 51 | 52 | class LLVMDumper { 53 | private: 54 | LLVMCompiler *compiler; 55 | llvm::Module *M; 56 | 57 | // types. 58 | llvm::Type *Ty_str_ptr; 59 | llvm::StructType *Ty_constant_value; 60 | llvm::StructType *Ty_constant_type; 61 | llvm::Type *Ty_constant_type_ptr; 62 | llvm::StructType *Ty_constant_num_type; 63 | llvm::Constant *num_padding; 64 | llvm::StructType *Ty_constant_bool_type; 65 | llvm::Constant *bool_padding; 66 | llvm::StructType *Ty_constant_str_type; 67 | llvm::Constant *str_padding; 68 | llvm::StructType *Ty_jit_LocVar; 69 | llvm::Type *Ty_jit_LocVar_ptr; 70 | llvm::StructType *Ty_jit_proto; 71 | llvm::Type *Ty_jit_proto_ptr; 72 | llvm::FunctionType *lua_func_type; 73 | llvm::Type *lua_func_type_ptr; 74 | 75 | public: 76 | LLVMDumper(LLVMCompiler *compiler); 77 | 78 | void dump(const char *output, lua_State *L, Proto *p, int stripping); 79 | 80 | llvm::LLVMContext& getCtx() const { 81 | return compiler->getCtx(); 82 | } 83 | 84 | private: 85 | llvm::Constant *get_ptr(llvm::Constant *val); 86 | 87 | llvm::Constant *get_global_str(const char *str); 88 | 89 | llvm::GlobalVariable *dump_constants(Proto *p); 90 | 91 | llvm::GlobalVariable *dump_locvars(Proto *p); 92 | 93 | llvm::GlobalVariable *dump_upvalues(Proto *p); 94 | 95 | llvm::Constant *dump_proto(Proto *p); 96 | 97 | void dump_standalone(Proto *p); 98 | 99 | void dump_lua_module(Proto *p, std::string mod_name); 100 | 101 | }; 102 | #endif 103 | 104 | -------------------------------------------------------------------------------- /llvm-lua/TODO: -------------------------------------------------------------------------------- 1 | 2 | optimizations: 3 | * When the internal index/limit/step variable of a OP_FORLOOP get moved to the C-Stack the space on the Lua-stack is unused. We should be able to decrease the maxstacksize by re-using those stack slots. 4 | * Try to inline some table/global lookups if they have a constant key. 5 | 6 | -------------------------------------------------------------------------------- /llvm-lua/bin2c.c: -------------------------------------------------------------------------------- 1 | /* 2 | * bin2c.c 3 | * 4 | * convert a binary file into a C source vector 5 | * 6 | * THE "BEER-WARE LICENSE" (Revision 3.1415): 7 | * sandro AT sigala DOT it wrote this file. As long as you retain this notice you can do 8 | * whatever you want with this stuff. If we meet some day, and you think this stuff is 9 | * worth it, you can buy me a beer in return. Sandro Sigala 10 | * 11 | * syntax: bin2c [-c] [-z] 12 | * 13 | * -c add the "const" keyword to definition 14 | * -z terminate the array with a zero (useful for embedded C strings) 15 | * 16 | * examples: 17 | * bin2c -c myimage.png myimage_png.cpp 18 | * bin2c -z sometext.txt sometext_txt.cpp 19 | */ 20 | 21 | #include 22 | #include 23 | #include 24 | #include 25 | 26 | #ifndef PATH_MAX 27 | #define PATH_MAX 1024 28 | #endif 29 | 30 | int useconst = 0; 31 | int zeroterminated = 0; 32 | 33 | int myfgetc(FILE *f) 34 | { 35 | int c = fgetc(f); 36 | if (c == EOF && zeroterminated) 37 | { 38 | zeroterminated = 0; 39 | return 0; 40 | } 41 | return c; 42 | } 43 | 44 | void process(const char *ifname, const char *ofname) 45 | { 46 | FILE *ifile, *ofile; 47 | ifile = fopen(ifname, "rb"); 48 | if (ifile == NULL) 49 | { 50 | fprintf(stderr, "cannot open %s for reading\n", ifname); 51 | exit(1); 52 | } 53 | ofile = fopen(ofname, "wb"); 54 | if (ofile == NULL) 55 | { 56 | fprintf(stderr, "cannot open %s for writing\n", ofname); 57 | exit(1); 58 | } 59 | char buf[PATH_MAX], *p; 60 | const char *cp; 61 | if ((cp = strrchr(ifname, '/')) != NULL) 62 | { 63 | ++cp; 64 | } else { 65 | if ((cp = strrchr(ifname, '\\')) != NULL) 66 | ++cp; 67 | else 68 | cp = ifname; 69 | } 70 | strcpy(buf, cp); 71 | for (p = buf; *p != '\0'; ++p) 72 | { 73 | if (!isalnum(*p)) 74 | *p = '_'; 75 | } 76 | fprintf(ofile, "static %sunsigned char %s[] = {\n", useconst ? "const " : "", buf); 77 | int c, col = 1; 78 | while ((c = myfgetc(ifile)) != EOF) 79 | { 80 | if (col >= 78 - 6) 81 | { 82 | fputc('\n', ofile); 83 | col = 1; 84 | } 85 | fprintf(ofile, "0x%.2x,", c); 86 | col += 6; 87 | } 88 | fprintf(ofile, "\n};\n"); 89 | 90 | fclose(ifile); 91 | fclose(ofile); 92 | } 93 | 94 | void usage(void) 95 | { 96 | fprintf(stderr, "usage: bin2c [-cz] \n"); 97 | exit(1); 98 | } 99 | 100 | int main(int argc, char **argv) 101 | { 102 | while (argc > 3) 103 | { 104 | if (!strcmp(argv[1], "-c")) 105 | { 106 | useconst = 1; 107 | --argc; 108 | ++argv; 109 | } else if (!strcmp(argv[1], "-z")) 110 | { 111 | zeroterminated = 1; 112 | --argc; 113 | ++argv; 114 | } else { 115 | usage(); 116 | } 117 | } 118 | if (argc != 3) 119 | { 120 | usage(); 121 | } 122 | process(argv[1], argv[2]); 123 | return 0; 124 | } 125 | 126 | -------------------------------------------------------------------------------- /llvm-lua/compile_all.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # 3 | 4 | OPTS="" 5 | FILES="" 6 | # parse command line parameters. 7 | for arg in "$@" ; do 8 | case "$arg" in 9 | -*) OPTS="$OPTS $arg" ;; 10 | *) FILES="$FILES $arg" ;; 11 | esac 12 | done 13 | 14 | for script in $FILES; do 15 | echo "Compiling script: $script" 16 | lua-compiler $OPTS $script 17 | #./lua-compiler $OPTS $script 18 | done 19 | 20 | -------------------------------------------------------------------------------- /llvm-lua/hook_parser.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** See Copyright Notice in lua.h 3 | */ 4 | 5 | /* 6 | * hook_parser.c - Add a hook to the parser in ldo.c 7 | * 8 | * Most of this code is from ldo.c 9 | */ 10 | 11 | #ifdef __cplusplus 12 | extern "C" { 13 | #endif 14 | 15 | #if !ENABLE_PARSER_HOOK 16 | 17 | #include "ldo.c" 18 | 19 | int llvm_precall_lua (lua_State *L, StkId func, int nresults) { 20 | return luaD_precall_lua(L, func, nresults); 21 | } 22 | 23 | #else 24 | 25 | #include "llvm_compiler.h" 26 | 27 | #define luaD_protectedparser luaD_protectedparser_old 28 | #include "ldo.c" 29 | #undef luaD_protectedparser 30 | 31 | static void llvm_f_parser (lua_State *L, void *ud) { 32 | int i; 33 | Proto *tf; 34 | Closure *cl; 35 | struct SParser *p = cast(struct SParser *, ud); 36 | int c = luaZ_lookahead(p->z); 37 | luaC_checkGC(L); 38 | set_block_gc(L); /* stop collector during parsing */ 39 | tf = ((c == LUA_SIGNATURE[0]) ? luaU_undump : luaY_parser)(L, p->z, 40 | &p->buff, p->name); 41 | llvm_compiler_compile_all(L, tf); 42 | cl = luaF_newLclosure(L, tf->nups, hvalue(gt(L))); 43 | cl->l.p = tf; 44 | for (i = 0; i < tf->nups; i++) /* initialize eventual upvalues */ 45 | cl->l.upvals[i] = luaF_newupval(L); 46 | setclvalue(L, L->top, cl); 47 | incr_top(L); 48 | unset_block_gc(L); 49 | } 50 | 51 | 52 | int luaD_protectedparser (lua_State *L, ZIO *z, const char *name) { 53 | struct SParser p; 54 | int status; 55 | p.z = z; p.name = name; 56 | luaZ_initbuffer(L, &p.buff); 57 | status = luaD_pcall(L, llvm_f_parser, &p, savestack(L, L->top), L->errfunc); 58 | luaZ_freebuffer(L, &p.buff); 59 | return status; 60 | } 61 | 62 | int llvm_precall_jit (lua_State *L, StkId func, int nresults) { 63 | Closure *cl; 64 | ptrdiff_t funcr; 65 | CallInfo *ci; 66 | StkId st, base; 67 | Proto *p; 68 | 69 | funcr = savestack(L, func); 70 | cl = clvalue(func); 71 | p = cl->l.p; 72 | luaD_checkstack(L, p->maxstacksize); 73 | func = restorestack(L, funcr); 74 | base = func + 1; 75 | if (L->top > base + p->numparams) 76 | L->top = base + p->numparams; 77 | ci = L->ci; /* now `enter' new function */ 78 | ci->func = func; 79 | L->base = ci->base = base; 80 | ci->top = L->base + p->maxstacksize; 81 | lua_assert(ci->top <= L->stack_last); 82 | L->savedpc = p->code; /* starting point */ 83 | ci->nresults = nresults; 84 | for (st = L->top; st < ci->top; st++) 85 | setnilvalue(st); 86 | L->top = ci->top; 87 | if (L->hookmask & LUA_MASKCALL) { 88 | L->savedpc++; /* hooks assume 'pc' is already incremented */ 89 | luaD_callhook(L, LUA_HOOKCALL, -1); 90 | L->savedpc--; /* correct 'pc' */ 91 | } 92 | return (p->jit_func)(L); /* do the actual call */ 93 | } 94 | 95 | int llvm_precall_jit_vararg (lua_State *L, StkId func, int nresults) { 96 | Closure *cl; 97 | ptrdiff_t funcr; 98 | CallInfo *ci; 99 | StkId st, base; 100 | Proto *p; 101 | int nargs; 102 | 103 | funcr = savestack(L, func); 104 | cl = clvalue(func); 105 | p = cl->l.p; 106 | luaD_checkstack(L, p->maxstacksize); 107 | func = restorestack(L, funcr); 108 | nargs = cast_int(L->top - func) - 1; 109 | base = adjust_varargs(L, p, nargs); 110 | func = restorestack(L, funcr); /* previous call may change the stack */ 111 | ci = L->ci; /* now `enter' new function */ 112 | ci->func = func; 113 | L->base = ci->base = base; 114 | ci->top = L->base + p->maxstacksize; 115 | lua_assert(ci->top <= L->stack_last); 116 | L->savedpc = p->code; /* starting point */ 117 | ci->nresults = nresults; 118 | for (st = L->top; st < ci->top; st++) 119 | setnilvalue(st); 120 | L->top = ci->top; 121 | if (L->hookmask & LUA_MASKCALL) { 122 | L->savedpc++; /* hooks assume 'pc' is already incremented */ 123 | luaD_callhook(L, LUA_HOOKCALL, -1); 124 | L->savedpc--; /* correct 'pc' */ 125 | } 126 | return (p->jit_func)(L); /* do the actual call */ 127 | } 128 | 129 | int llvm_precall_lua (lua_State *L, StkId func, int nresults) { 130 | Closure *cl; 131 | Proto *p; 132 | 133 | cl = clvalue(func); 134 | p = cl->l.p; 135 | /* check if Function needs to be compiled. */ 136 | if(p->jit_func == NULL) { 137 | llvm_compiler_compile(L, p); 138 | } 139 | if(p->jit_func != NULL) { 140 | if (!p->is_vararg) { /* no varargs? */ 141 | cl->l.precall = llvm_precall_jit; 142 | return llvm_precall_jit(L, func, nresults); 143 | } else { 144 | cl->l.precall = llvm_precall_jit_vararg; 145 | return llvm_precall_jit_vararg(L, func, nresults); 146 | } 147 | } 148 | /* function didn't compile, fall-back to lua interpreter */ 149 | cl->l.precall = luaD_precall_lua; 150 | return luaD_precall_lua(L, func, nresults); 151 | } 152 | 153 | #endif 154 | 155 | #ifdef __cplusplus 156 | } 157 | #endif 158 | 159 | -------------------------------------------------------------------------------- /llvm-lua/llvm-lua.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2009 Robert G. Jakabosky 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy 5 | of this software and associated documentation files (the "Software"), to deal 6 | in the Software without restriction, including without limitation the rights 7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | copies of the Software, and to permit persons to whom the Software is 9 | furnished to do so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in 12 | all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | THE SOFTWARE. 21 | 22 | MIT License: http://www.opensource.org/licenses/mit-license.php 23 | */ 24 | 25 | #include 26 | 27 | #include "llvm_compiler.h" 28 | #include "lua_interpreter.h" 29 | 30 | #include "llvm/Support/CommandLine.h" 31 | #include "llvm/Support/ManagedStatic.h" 32 | 33 | namespace { 34 | llvm::cl::opt 35 | InputFile(llvm::cl::Positional, llvm::cl::desc("