├── .gitignore ├── .gitmodules ├── LICENSE ├── Makefile ├── README.md ├── ch.png ├── ch2.png └── src ├── Binding.h ├── Bindings.cpp ├── CoreInfo.cpp ├── CoreInfo.h ├── GameControllerDB.inl ├── ImguiLibretro.cpp ├── ImguiLibretro.h ├── Memory.cpp ├── Memory.h ├── Set.cpp ├── Set.h ├── Snapshot.cpp ├── Snapshot.h ├── components ├── Audio.cpp ├── Audio.h ├── Input.cpp ├── Input.h ├── Video.cpp ├── Video.h └── controller.inl ├── debugbreak.h ├── dynlib ├── dynlib.c └── dynlib.h ├── fnkdat ├── fnkdat.c └── fnkdat.h ├── imguiext ├── IconsFontAwesome_c.h ├── IconsKenney_c.h ├── IconsMaterialDesign_c.h ├── dirent_portable.h ├── imgui_memory_editor.h ├── imguial_button.h ├── imguial_fonts.cpp ├── imguial_fonts.h ├── imguial_log.cpp ├── imguial_log.h ├── imguial_term.cpp ├── imguial_term.h ├── imguidock.cpp ├── imguidock.h ├── imguifilesystem.cpp ├── imguifilesystem.h ├── imguihelper.cpp └── imguihelper.h ├── json.hpp ├── libretro ├── Components.h ├── Core.cpp ├── Core.h ├── CoreManager.cpp ├── CoreManager.h ├── libretro.h └── libretropp.h ├── lua-5.3.5 ├── Makefile ├── README ├── doc │ ├── contents.html │ ├── index.css │ ├── logo.gif │ ├── lua.1 │ ├── lua.css │ ├── luac.1 │ ├── manual.css │ ├── manual.html │ ├── osi-certified-72x60.png │ └── readme.html └── src │ ├── Makefile │ ├── lapi.c │ ├── lapi.h │ ├── lauxlib.c │ ├── lauxlib.h │ ├── lbaselib.c │ ├── lbitlib.c │ ├── lcode.c │ ├── lcode.h │ ├── lcorolib.c │ ├── lctype.c │ ├── lctype.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 │ ├── lprefix.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 │ ├── lua.hpp │ ├── luac.c │ ├── luaconf.h │ ├── lualib.h │ ├── lundump.c │ ├── lundump.h │ ├── lutf8lib.c │ ├── lvm.c │ ├── lvm.h │ ├── lzio.c │ └── lzio.h ├── main.cpp └── speex ├── arch.h ├── fixed_arm4.h ├── fixed_arm5e.h ├── fixed_bfin.h ├── fixed_debug.h ├── fixed_generic.h ├── resample.c ├── resample_neon.h ├── resample_sse.h ├── speex_resampler.h └── stack_alloc.h /.gitignore: -------------------------------------------------------------------------------- 1 | etc/* 2 | .vscode/* 3 | imgui.ini 4 | imguidock.ini 5 | config.json 6 | *.o 7 | *.exe 8 | *.dll 9 | *.so 10 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "src/imgui"] 2 | path = src/imgui 3 | url = https://github.com/ocornut/imgui.git 4 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 Andre Leiradella 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | # Platform setup 2 | ifeq ($(shell uname -a),) 3 | SOEXT=.dll 4 | LIBS=-lOpenGL32 5 | else ifneq ($(findstring MINGW,$(shell uname -a)),) 6 | SOEXT=.dll 7 | LIBS=-lOpenGL32 8 | else 9 | SOEXT=.so 10 | LIBS=-lGL -ldl 11 | endif 12 | 13 | # Toolset setup 14 | CC=gcc 15 | CXX=g++ 16 | INCLUDES=-Isrc -Isrc/imgui -Isrc/imgui/examples -Isrc/lua-5.3.5/src -include debugbreak.h 17 | DEFINES =-DIMGUI_DISABLE_WIN32_DEFAULT_IME_FUNCS -D"IM_ASSERT(x)=do{if(!(x))debug_break();}while(0)" 18 | DEFINES+=-DIMGUIAL_FONTS_PROGGY_TINY -DIMGUIAL_FONTS_FONT_AWESOME -DIMGUIAL_FONTS_MATERIAL_DESIGN 19 | DEFINES+=-DOUTSIDE_SPEEX -DRANDOM_PREFIX=speex -DEXPORT= -D_USE_SSE2 -DFIXED_POINT 20 | DEFINES+=-DPACKAGE=\"cheevoshunter\" 21 | #CCFLAGS=-Wall -O2 $(INCLUDES) $(DEFINES) `sdl2-config --cflags` 22 | CCFLAGS=-Wall -O0 -g $(INCLUDES) $(DEFINES) `sdl2-config --cflags` 23 | CXXFLAGS=$(CCFLAGS) -std=c++11 -fPIC 24 | LDFLAGS= 25 | 26 | # lua 27 | LUA_OBJS=\ 28 | src/lua-5.3.5/src/lapi.o src/lua-5.3.5/src/lcode.o src/lua-5.3.5/src/lctype.o src/lua-5.3.5/src/ldebug.o \ 29 | src/lua-5.3.5/src/ldo.o src/lua-5.3.5/src/ldump.o src/lua-5.3.5/src/lfunc.o src/lua-5.3.5/src/lgc.o src/lua-5.3.5/src/llex.o \ 30 | src/lua-5.3.5/src/lmem.o src/lua-5.3.5/src/lobject.o src/lua-5.3.5/src/lopcodes.o src/lua-5.3.5/src/lparser.o \ 31 | src/lua-5.3.5/src/lstate.o src/lua-5.3.5/src/lstring.o src/lua-5.3.5/src/ltable.o src/lua-5.3.5/src/ltm.o \ 32 | src/lua-5.3.5/src/lundump.o src/lua-5.3.5/src/lvm.o src/lua-5.3.5/src/lzio.o src/lua-5.3.5/src/lauxlib.o \ 33 | src/lua-5.3.5/src/lbaselib.o src/lua-5.3.5/src/lbitlib.o src/lua-5.3.5/src/lcorolib.o src/lua-5.3.5/src/ldblib.o \ 34 | src/lua-5.3.5/src/liolib.o src/lua-5.3.5/src/lmathlib.o src/lua-5.3.5/src/loslib.o src/lua-5.3.5/src/lstrlib.o \ 35 | src/lua-5.3.5/src/ltablib.o src/lua-5.3.5/src/lutf8lib.o src/lua-5.3.5/src/loadlib.o src/lua-5.3.5/src/linit.o 36 | 37 | # ch 38 | CH_OBJS=\ 39 | src/main.o src/ImguiLibretro.o src/CoreInfo.o src/Memory.o src/Set.o src/Snapshot.o \ 40 | src/libretro/Core.o src/libretro/CoreManager.o \ 41 | src/components/Audio.o src/components/Input.o src/components/Video.o \ 42 | src/dynlib/dynlib.o src/fnkdat/fnkdat.o src/speex/resample.o 43 | 44 | # imgui 45 | IMGUI_OBJS=\ 46 | src/imgui/imgui.o src/imgui/imgui_widgets.o src/imgui/imgui_demo.o src/imgui/imgui_draw.o \ 47 | src/imgui/examples/imgui_impl_sdl.o src/imgui/examples/imgui_impl_opengl2.o 48 | 49 | # imgui extras 50 | IMGUIEXT_OBJS=\ 51 | src/imguiext/imguial_fonts.o src/imguiext/imguifilesystem.o \ 52 | src/imguiext/imguial_term.o 53 | 54 | %.o: %.cpp 55 | $(CXX) $(CXXFLAGS) -c $< -o $@ 56 | 57 | %.o: %.c 58 | $(CC) $(CCFLAGS) -c $< -o $@ 59 | 60 | all: ch 61 | 62 | ch: $(CH_OBJS) $(IMGUI_OBJS) $(IMGUIEXT_OBJS) $(LUA_OBJS) 63 | $(CXX) $(LDFLAGS) -o $@ $+ $(CH_LIBS) `sdl2-config --libs` $(LIBS) 64 | 65 | #imgui$(SOEXT): $(IMGUI_OBJS) 66 | # $(CXX) -shared $(LDFLAGS) -o $@ $(IMGUI_OBJS) $(IMGUI_LIBS) 67 | 68 | #imguiext$(SOEXT): imgui$(SOEXT) $(IMGUIEXT_OBJS) 69 | # $(CXX) -shared $(LDFLAGS) -o $@ $(IMGUIEXT_OBJS) $(IMGUIEXT_LIBS) 70 | 71 | clean: 72 | rm -f ch $(CH_OBJS) $(IMGUI_OBJS) $(IMGUIEXT_OBJS) $(LUA_OBJS) 73 | 74 | .PHONY: clean 75 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Cheevos Hunter 2 | 3 | This was my [libretro](https://www.libretro.com/index.php/api/) frontend with integrated tooling to hunt for achievements, just like the tooling found in the [Retro Achievements](http://retroachievements.org/) official emulators. 4 | 5 | ![Cheevos Hunter](https://raw.githubusercontent.com/leiradel/CheevosHunter/master/ch.png) 6 | ![Cheevos Hunter](https://raw.githubusercontent.com/leiradel/CheevosHunter/master/ch2.png) 7 | 8 | I've abandoned this project in favor of integrating the tooling in [RetroArch](https://github.com/fr500/RetroArch/tree/hunter). However, this code base has some interesting things worth sharing: 9 | 10 | * `src/libretro/BareCore.[h|cpp]`: A C++ class with methods that map 1:1 to the libretro API implemented in libretro cores. 11 | * `src/libretro/Core.[h|cpp]`: A wrap around BareCore, providing higher level functionality such as initializing a core, executing one emulated frame, and destroying the core. It supports multiple concurrent running cores, and uses composition to implement the platform specific code to display video frames and playing audio frames, reading input etc. Ready to use components that work with SDL2 can be found in `src/ImguiLibretro.[h|cpp]`. 12 | * `src/libretro/Components.h`: The components that must be implemented to use with a Core. 13 | 14 | A notable missing feature of this frontend is support for `RETRO_ENVIRONMENT_SET_HW_RENDER`. PRs are welcome. -------------------------------------------------------------------------------- /ch.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leiradel/CheevosHunter/a7d0145c7617caf63d42b134a831707f10c1d27b/ch.png -------------------------------------------------------------------------------- /ch2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leiradel/CheevosHunter/a7d0145c7617caf63d42b134a831707f10c1d27b/ch2.png -------------------------------------------------------------------------------- /src/Binding.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | void registerBindings(lua_State* const L); 6 | -------------------------------------------------------------------------------- /src/Bindings.cpp: -------------------------------------------------------------------------------- 1 | #include "Bindings.h" 2 | #include "Memory.h" 3 | #include "Snapshot.h" 4 | 5 | #include 6 | #include 7 | 8 | #define METATABLE_SNAPSHOT "snapshot" 9 | 10 | struct LuaSnapshot { 11 | Snapshot* snapshot; 12 | Snapshot::Size size; 13 | Snapshot::Format format; 14 | }; 15 | 16 | static int snapshotIndex(lua_State* const L) { 17 | size_t length; 18 | char const* key; 19 | 20 | key = luaL_checklstring(L, 2, &length); 21 | 22 | if (length == 4 && !strcmp(key, "size")) { 23 | lua_pushcfunction(L, image_size); 24 | return 1; 25 | } 26 | else if (length == 9 && !strcmp(key, "blit_nobg")) { 27 | lua_pushcfunction(L, image_blit_nobg); 28 | return 1; 29 | } 30 | 31 | return luaL_error(L, "unknown " METATABLE_NAME " method %s", key); 32 | } 33 | 34 | static int snapshotGc(lua_State* const L) { 35 | rl_image_t const* const self = (rl_image_t*)lua_touserdata(L, 1); 36 | rl_image_destroy(self); 37 | return 0; 38 | } 39 | 40 | static int click(lua_State* const L) { 41 | LuaSnapshot* const self = static_castlua_newuserdata(L, sizeof(LuaSnapshot)); 42 | 43 | //self->snapshot = Memory::click(); 44 | self->size = Snapshot::Size::_8; 45 | self->format = Snapshot::Format::UIntLittleEndian; 46 | 47 | if (luaL_newmetatable(L, METATABLE_SNAPSHOT) != 0) { 48 | lua_pushcfunction(L, snapshotIndex); 49 | lua_setfield(L, -2, "__index"); 50 | lua_pushcfunction(L, snapshotGc); 51 | lua_setfield(L, -2, "__gc"); 52 | } 53 | 54 | lua_setmetatable(L, -2); 55 | return 1; 56 | } 57 | 58 | void registerBindings(lua_State* const L) { 59 | static luaL_Reg const functions[] = { 60 | {"click", click}, 61 | {NULL, NULL} 62 | }; 63 | 64 | luaL_setfuncs(L, functions); 65 | } 66 | -------------------------------------------------------------------------------- /src/CoreInfo.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "libretro/CoreManager.h" 4 | 5 | void drawCoreInfo(libretro::CoreManager const* const core); 6 | -------------------------------------------------------------------------------- /src/ImguiLibretro.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "libretro/Components.h" 4 | #include "imguiext/imguial_term.h" 5 | #include "speex/speex_resampler.h" 6 | 7 | #include "json.hpp" 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | 15 | #include 16 | #include 17 | 18 | using json = nlohmann::json; 19 | 20 | class Logger: public libretro::LoggerComponent 21 | { 22 | public: 23 | Logger() {} 24 | 25 | bool init(); 26 | void destroy(); 27 | void reset(); 28 | void draw(); 29 | 30 | virtual void vprintf(enum retro_log_level level, const char* fmt, va_list args) override; 31 | 32 | protected: 33 | static char const* const s_actions[]; 34 | 35 | ImGuiAl::BufferedLog<65536> _logger; 36 | }; 37 | 38 | class Config: public libretro::ConfigComponent 39 | { 40 | public: 41 | bool init(libretro::LoggerComponent* logger, json* json); 42 | void destroy(); 43 | void reset(); 44 | void draw(); 45 | 46 | virtual std::string const& getCoreAssetsDirectory() override; 47 | virtual std::string const& getSaveDirectory() override; 48 | virtual std::string const& getSystemPath() override; 49 | 50 | virtual void setVariables(std::vector const& variables) override; 51 | virtual bool varUpdated() override; 52 | virtual std::string const& getVariable(std::string const& variable) override; 53 | 54 | protected: 55 | struct Variable 56 | { 57 | std::string key; 58 | std::string name; 59 | std::string value; 60 | int selected; 61 | std::vector options; 62 | }; 63 | 64 | libretro::LoggerComponent* _logger; 65 | bool _opened; 66 | std::string _systemPath; 67 | std::string _coreAssetsPath; 68 | std::string _savePath; 69 | 70 | json* _json; 71 | 72 | std::map _variables; 73 | bool _updated; 74 | }; 75 | 76 | class Loader: public libretro::LoaderComponent 77 | { 78 | public: 79 | bool init(libretro::LoggerComponent* logger); 80 | void destroy(); 81 | void reset(); 82 | 83 | virtual void* load(size_t* size, std::string const& path) override; 84 | virtual void free(void* data) override; 85 | 86 | protected: 87 | libretro::LoggerComponent* _logger; 88 | }; 89 | -------------------------------------------------------------------------------- /src/Memory.cpp: -------------------------------------------------------------------------------- 1 | #include "Memory.h" 2 | 3 | #include "imguiext/imguial_fonts.h" 4 | #include "imguiext/imguidock.h" 5 | #include "imguiext/imgui_memory_editor.h" 6 | 7 | #include 8 | 9 | bool Memory::init(libretro::CoreManager* core) 10 | { 11 | _core = core; 12 | _selected = 0; 13 | return true; 14 | } 15 | 16 | void Memory::destroy() 17 | { 18 | _map.clear(); 19 | } 20 | 21 | void Memory::draw(bool running) 22 | { 23 | if (ImGui::Begin(ICON_FA_MICROCHIP " Memory")) 24 | { 25 | if (running && _map.size() == 0) 26 | { 27 | addMemory(RETRO_MEMORY_SYSTEM_RAM, "System RAM "); 28 | addMemory(RETRO_MEMORY_SAVE_RAM, "Save RAM "); 29 | addMemory(RETRO_MEMORY_VIDEO_RAM, "Video RAM "); 30 | addMemory(RETRO_MEMORY_RTC, "RTC RAM "); 31 | 32 | std::vector const& map = _core->getMemoryMap(); 33 | 34 | for (auto const& desc : map) 35 | { 36 | if (desc.ptr == nullptr || desc.len == 0) 37 | { 38 | continue; 39 | } 40 | 41 | char name[64]; 42 | int numWritten = snprintf(name, sizeof(name), "@%08X ", (unsigned)desc.start); 43 | asMemorySize(name + numWritten, sizeof(name) - numWritten, desc.len); 44 | 45 | Region region; 46 | region.address = static_cast(desc.start); 47 | region.data = static_cast(static_cast(desc.ptr) + desc.offset); 48 | region.size = desc.len; 49 | region.name = name; 50 | 51 | _map.emplace_back(std::move(region)); 52 | } 53 | } 54 | 55 | struct Getter 56 | { 57 | static bool description(void* data, int idx, const char** out_text) 58 | { 59 | auto const map = (std::vector*)data; 60 | *out_text = (*map)[idx].name.c_str(); 61 | 62 | return true; 63 | } 64 | }; 65 | 66 | ImGui::Combo("Region", &_selected, Getter::description, (void*)&_map, _map.size()); 67 | 68 | if (static_cast(_selected) < _map.size()) 69 | { 70 | static MemoryEditor editor; 71 | 72 | Region& region = _map[_selected]; 73 | editor.Draw(region.name.c_str(), (unsigned char*)region.data, region.size); 74 | } 75 | } 76 | 77 | ImGui::End(); 78 | } 79 | 80 | void Memory::reset() 81 | { 82 | _map.clear(); 83 | _selected = 0; 84 | } 85 | 86 | Snapshot Memory::click() const { 87 | if (static_cast(_selected) < _map.size()) 88 | { 89 | auto& region = _map[_selected]; 90 | return Snapshot(region.address, region.data, region.size); 91 | } 92 | else 93 | { 94 | return Snapshot(0, nullptr, 0); 95 | } 96 | } 97 | 98 | void Memory::asMemorySize(char* str, size_t size, size_t numBytes) 99 | { 100 | static char const* const units[] = {"bytes", "KiB", "MiB", "GiB", nullptr}; 101 | 102 | for (int unit = 0; units[unit] != nullptr; unit++) 103 | { 104 | size_t rest = numBytes % 1024; 105 | 106 | if (rest != 0) 107 | { 108 | snprintf(str, size, "%4zu %s", numBytes, units[unit]); 109 | return; 110 | } 111 | 112 | numBytes /= 1024; 113 | } 114 | 115 | snprintf(str, size, "%zu GiB", numBytes / (1024 * 1024 * 1024)); 116 | } 117 | 118 | void Memory::addMemory(unsigned id, char const* name) 119 | { 120 | Region region; 121 | 122 | region.data = _core->getMemoryData(id); 123 | region.size = _core->getMemorySize(id); 124 | 125 | if (region.data == nullptr || region.size == 0) 126 | { 127 | return; 128 | } 129 | 130 | region.address = 0; 131 | 132 | char buffer[64]; 133 | int numWritten = snprintf(buffer, sizeof(buffer), "%s", name); 134 | asMemorySize(buffer + numWritten, sizeof(buffer) - numWritten, region.size); 135 | 136 | region.name = buffer; 137 | _map.emplace_back(std::move(region)); 138 | } 139 | -------------------------------------------------------------------------------- /src/Memory.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "libretro/CoreManager.h" 4 | 5 | #include "imgui/imgui.h" 6 | 7 | #include "Snapshot.h" 8 | 9 | #include 10 | #include 11 | #include 12 | 13 | class Memory 14 | { 15 | public: 16 | bool init(libretro::CoreManager* core); 17 | void destroy(); 18 | void draw(bool running); 19 | 20 | void reset(); 21 | 22 | Snapshot click() const; 23 | 24 | protected: 25 | struct Region 26 | { 27 | std::string name; 28 | uint32_t address; 29 | void* data; 30 | size_t size; 31 | }; 32 | 33 | static void asMemorySize(char* str, size_t size, size_t numBytes); 34 | void addMemory(unsigned id, char const* name); 35 | 36 | void drawMemory(bool running); 37 | void drawFilters(); 38 | 39 | libretro::CoreManager* _core; 40 | std::vector _map; 41 | int _selected; 42 | }; 43 | -------------------------------------------------------------------------------- /src/Set.cpp: -------------------------------------------------------------------------------- 1 | #include "Set.h" 2 | 3 | #include 4 | 5 | Set::Set(std::vector&& elements) : _elements(std::move(elements)) { 6 | std::sort(_elements.begin(), _elements.end(), [](uint32_t const& a, uint32_t const& b) -> bool { 7 | return a < b; 8 | }); 9 | } 10 | 11 | Set::Set(Set&& other) : _elements(std::move(other._elements)) {} 12 | 13 | bool Set::contains(uint32_t element) const 14 | { 15 | return std::binary_search(_elements.begin(), _elements.end(), element); 16 | } 17 | 18 | Set Set::union_(const Set& other) 19 | { 20 | Set result; 21 | result._elements.reserve(_elements.size() + other._elements.size()); 22 | 23 | std::set_union(_elements.begin(), 24 | _elements.end(), 25 | other._elements.begin(), 26 | other._elements.end(), 27 | std::inserter(result._elements, result._elements.begin())); 28 | 29 | result._elements.shrink_to_fit(); 30 | return result; 31 | } 32 | 33 | Set Set::intersection(const Set& other) 34 | { 35 | Set result; 36 | result._elements.reserve(std::min(_elements.size(), other._elements.size())); 37 | 38 | std::set_intersection(_elements.begin(), 39 | _elements.end(), 40 | other._elements.begin(), 41 | other._elements.end(), 42 | std::inserter(result._elements, result._elements.begin())); 43 | 44 | result._elements.shrink_to_fit(); 45 | return result; 46 | } 47 | 48 | Set Set::subtraction(const Set& other) 49 | { 50 | Set result; 51 | result._elements.reserve(_elements.size()); 52 | 53 | std::set_difference(_elements.begin(), 54 | _elements.end(), 55 | other._elements.begin(), 56 | other._elements.end(), 57 | std::inserter(result._elements, result._elements.begin())); 58 | 59 | result._elements.shrink_to_fit(); 60 | return result; 61 | } 62 | -------------------------------------------------------------------------------- /src/Set.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | class Set 8 | { 9 | public: 10 | Set() = default; 11 | Set(std::vector&& elements); 12 | Set(Set&& other); 13 | 14 | bool contains(uint32_t element) const; 15 | 16 | Set union_(const Set& other); 17 | Set intersection(const Set& other); 18 | Set subtraction(const Set& other); 19 | 20 | std::vector::const_iterator begin() const 21 | { 22 | return _elements.begin(); 23 | } 24 | 25 | std::vector::const_iterator end() const 26 | { 27 | return _elements.end(); 28 | } 29 | 30 | protected: 31 | std::vector _elements; 32 | }; 33 | -------------------------------------------------------------------------------- /src/Snapshot.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Set.h" 4 | 5 | #include 6 | #include 7 | 8 | class Snapshot 9 | { 10 | public: 11 | enum class Size 12 | { 13 | _8, 14 | _16, 15 | _24, 16 | _32 17 | }; 18 | 19 | enum class Format 20 | { 21 | UIntLittleEndian, 22 | UIntBigEndian, 23 | BCDLittleEndian, 24 | BCDBigEndian 25 | }; 26 | 27 | enum class Operator 28 | { 29 | LessThan, 30 | LessEqual, 31 | GreaterThan, 32 | GreaterEqual, 33 | Equal, 34 | NotEqual 35 | }; 36 | 37 | Snapshot(uint32_t const address, const void* const data, size_t const size); 38 | 39 | uint32_t address() const { return _address; } 40 | size_t size() const { return _size; } 41 | 42 | Set filter(Size const bits, Format const format, Operator const op, uint32_t const value) const; 43 | Set filter(Size const bits, Format const format, Operator const op, Snapshot const& other) const; 44 | 45 | protected: 46 | uint32_t _address; 47 | void* _data; 48 | size_t _size; 49 | }; 50 | -------------------------------------------------------------------------------- /src/components/Audio.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "libretro/Components.h" 4 | #include "speex/speex_resampler.h" 5 | 6 | #include 7 | 8 | class Fifo { 9 | public: 10 | bool init(size_t const size); 11 | void destroy(); 12 | void reset(); 13 | 14 | void read(void* const data, size_t const size); 15 | void write(void const* const data, size_t const size); 16 | 17 | size_t size(); 18 | size_t occupied(); 19 | size_t free(); 20 | 21 | protected: 22 | SDL_mutex* _mutex; 23 | uint8_t* _buffer; 24 | size_t _size; 25 | size_t _avail; 26 | size_t _first; 27 | size_t _last; 28 | }; 29 | 30 | class Audio: public libretro::AudioComponent { 31 | public: 32 | bool init(libretro::LoggerComponent* const logger, double const sample_rate, Fifo* const fifo); 33 | void destroy(); 34 | void reset(); 35 | void draw(); 36 | 37 | virtual bool setRate(double const rate) override; 38 | virtual void mix(int16_t const* const samples, size_t const frames) override; 39 | 40 | protected: 41 | libretro::LoggerComponent* _logger; 42 | 43 | bool _mute; 44 | int16_t const* _samples; 45 | size_t _frames; 46 | float _min; 47 | float _max; 48 | 49 | double _sampleRate; 50 | double _coreRate; 51 | 52 | double _rateControlDelta; 53 | double _currentRatio; 54 | double _originalRatio; 55 | SpeexResamplerState* _resampler; 56 | 57 | Fifo* _fifo; 58 | }; 59 | -------------------------------------------------------------------------------- /src/components/Input.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "libretro/Components.h" 4 | 5 | #include 6 | #include 7 | #include 8 | 9 | #include 10 | #include 11 | 12 | class Input: public libretro::InputComponent 13 | { 14 | public: 15 | bool init(libretro::LoggerComponent* logger); 16 | void destroy(); 17 | void reset(); 18 | void draw(); 19 | 20 | void addController(int which); 21 | void processEvent(const SDL_Event* event); 22 | 23 | virtual void setInputDescriptors(std::vector const& descs) override; 24 | 25 | virtual void setControllerInfo(std::vector const& infos) override; 26 | virtual bool ctrlUpdated() override; 27 | virtual unsigned getController(unsigned port) override; 28 | 29 | virtual void poll() override; 30 | virtual int16_t read(unsigned port, unsigned device, unsigned index, unsigned id) override; 31 | 32 | protected: 33 | struct Pad 34 | { 35 | SDL_JoystickID id; 36 | SDL_GameController* controller; 37 | std::string controllerName; 38 | SDL_Joystick* joystick; 39 | std::string joystickName; 40 | int lastDir[6]; 41 | bool state[16]; 42 | float sensitivity; 43 | 44 | int port; 45 | unsigned devId; 46 | }; 47 | 48 | typedef libretro::InputDescriptor Descriptor; 49 | typedef libretro::ControllerDescription ControllerType; 50 | 51 | struct Controller 52 | { 53 | std::vector types; 54 | }; 55 | 56 | void drawPad(unsigned button); 57 | void addController(const SDL_Event* event); 58 | void removeController(const SDL_Event* event); 59 | void controllerButton(const SDL_Event* event); 60 | void controllerAxis(const SDL_Event* event); 61 | void keyboard(const SDL_Event* event); 62 | 63 | libretro::LoggerComponent* _logger; 64 | 65 | GLuint _texture; 66 | bool _updated; 67 | 68 | std::unordered_map _pads; 69 | std::vector _descriptors; 70 | std::vector _controllers; 71 | uint64_t _ports; 72 | std::vector _ids[64]; 73 | }; 74 | -------------------------------------------------------------------------------- /src/components/Video.cpp: -------------------------------------------------------------------------------- 1 | #include "Video.h" 2 | 3 | #include 4 | 5 | bool Video::init(libretro::LoggerComponent* logger) 6 | { 7 | _logger = logger; 8 | _texture = 0; 9 | _opened = true; 10 | _width = _height = 0; 11 | return true; 12 | } 13 | 14 | void Video::destroy() 15 | { 16 | if (_texture != 0) 17 | { 18 | glDeleteTextures(1, &_texture); 19 | } 20 | } 21 | 22 | void Video::reset() 23 | { 24 | } 25 | 26 | void Video::draw() 27 | { 28 | if (_texture != 0) 29 | { 30 | ImVec2 min = ImGui::GetWindowContentRegionMin(); 31 | ImVec2 max = ImGui::GetWindowContentRegionMax(); 32 | 33 | float height = max.y - min.y; 34 | float width = height * _aspect; 35 | 36 | if (width > max.x - min.x) 37 | { 38 | width = max.x - min.x; 39 | height = width / _aspect; 40 | } 41 | 42 | ImVec2 size = ImVec2(width, height); 43 | ImVec2 uv0 = ImVec2(0.0f, 0.0f); 44 | 45 | ImVec2 uv1 = ImVec2( 46 | (float)_width / _textureWidth, 47 | (float)_height / _textureHeight 48 | ); 49 | 50 | ImGui::Image((ImTextureID)(uintptr_t)_texture, size, uv0, uv1); 51 | } 52 | } 53 | 54 | bool Video::setGeometry(unsigned width, unsigned height, float aspect, enum retro_pixel_format pixelFormat) 55 | { 56 | if (_texture != 0) 57 | { 58 | glDeleteTextures(1, &_texture); 59 | } 60 | 61 | GLint previous_texture; 62 | glGetIntegerv(GL_TEXTURE_BINDING_2D, &previous_texture); 63 | 64 | glGenTextures(1, &_texture); 65 | glBindTexture(GL_TEXTURE_2D, _texture); 66 | 67 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); 68 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); 69 | 70 | switch (pixelFormat) 71 | { 72 | case RETRO_PIXEL_FORMAT_XRGB8888: 73 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); 74 | break; 75 | 76 | case RETRO_PIXEL_FORMAT_RGB565: 77 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, NULL); 78 | break; 79 | 80 | case RETRO_PIXEL_FORMAT_0RGB1555: 81 | default: 82 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_SHORT_1_5_5_5_REV, NULL); 83 | break; 84 | } 85 | 86 | glBindTexture(GL_TEXTURE_2D, previous_texture); 87 | _textureWidth = width; 88 | _textureHeight = height; 89 | _pixelFormat = pixelFormat; 90 | _aspect = aspect; 91 | 92 | _logger->printf(RETRO_LOG_DEBUG, "Geometry set to %u x %u (1:%f)", width, height, aspect); 93 | 94 | return true; 95 | } 96 | 97 | void Video::refresh(const void* data, unsigned width, unsigned height, size_t pitch) 98 | { 99 | if (data != NULL && data != RETRO_HW_FRAME_BUFFER_VALID) 100 | { 101 | GLint previous_texture; 102 | glGetIntegerv(GL_TEXTURE_BINDING_2D, &previous_texture); 103 | 104 | glBindTexture(GL_TEXTURE_2D, _texture); 105 | uint8_t* p = (uint8_t*)data; 106 | 107 | GLenum type; 108 | 109 | switch (_pixelFormat) 110 | { 111 | case RETRO_PIXEL_FORMAT_XRGB8888: 112 | { 113 | uint32_t* q = (uint32_t*)alloca(width * 4); 114 | 115 | if (q != NULL) 116 | { 117 | for (unsigned y = 0; y < height; y++) 118 | { 119 | uint32_t* r = q; 120 | uint32_t* s = (uint32_t*)p; 121 | 122 | for (unsigned x = 0; x < width; x++) 123 | { 124 | uint32_t color = *s++; 125 | uint32_t red = (color >> 16) & 255; 126 | uint32_t green = (color >> 8) & 255; 127 | uint32_t blue = color & 255; 128 | *r++ = 0xff000000UL | blue << 16 | green << 8 | red; 129 | } 130 | 131 | glTexSubImage2D(GL_TEXTURE_2D, 0, 0, y, width, 1, GL_RGBA, GL_UNSIGNED_BYTE, (void*)q); 132 | p += pitch; 133 | } 134 | } 135 | } 136 | 137 | goto end; 138 | 139 | case RETRO_PIXEL_FORMAT_RGB565: 140 | type = GL_UNSIGNED_SHORT_5_6_5; 141 | break; 142 | 143 | case RETRO_PIXEL_FORMAT_0RGB1555: 144 | default: 145 | type = GL_UNSIGNED_SHORT_1_5_5_5_REV; 146 | break; 147 | } 148 | 149 | for (unsigned y = 0; y < height; y++) 150 | { 151 | glTexSubImage2D(GL_TEXTURE_2D, 0, 0, y, width, 1, GL_RGB, type, (void*)p); 152 | p += pitch; 153 | } 154 | 155 | end: 156 | glBindTexture(GL_TEXTURE_2D, previous_texture); 157 | 158 | if (width != _width || height != _height) 159 | { 160 | _width = width; 161 | _height = height; 162 | 163 | _logger->printf(RETRO_LOG_DEBUG, "Video refreshed with geometry %u x %u", width, height); 164 | } 165 | } 166 | } 167 | 168 | uintptr_t Video::getCurrentFramebuffer() 169 | { 170 | return 0; 171 | } 172 | 173 | void Video::showMessage(std::string const& msg, unsigned frames) 174 | { 175 | _logger->printf(RETRO_LOG_INFO, "OSD message (%u): %s", frames, msg.c_str()); 176 | } 177 | -------------------------------------------------------------------------------- /src/components/Video.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "libretro/Components.h" 4 | 5 | #include 6 | #include 7 | 8 | class Video: public libretro::VideoComponent 9 | { 10 | public: 11 | bool init(libretro::LoggerComponent* logger); 12 | void destroy(); 13 | void reset(); 14 | void draw(); 15 | 16 | virtual bool setGeometry(unsigned width, unsigned height, float aspect, enum retro_pixel_format pixelFormat) override; 17 | virtual void refresh(const void* data, unsigned width, unsigned height, size_t pitch) override; 18 | 19 | virtual uintptr_t getCurrentFramebuffer() override; 20 | 21 | virtual void showMessage(std::string const& msg, unsigned frames) override; 22 | 23 | protected: 24 | libretro::LoggerComponent* _logger; 25 | GLuint _texture; 26 | unsigned _textureWidth; 27 | unsigned _textureHeight; 28 | enum retro_pixel_format _pixelFormat; 29 | 30 | bool _opened; 31 | unsigned _width; 32 | unsigned _height; 33 | float _aspect; 34 | }; 35 | -------------------------------------------------------------------------------- /src/debugbreak.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2011-2015, Scott Tsai 2 | * 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, 11 | * this list of conditions and the following disclaimer in the documentation 12 | * and/or other materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 15 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 18 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 19 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 20 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 21 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 22 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 23 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 24 | * POSSIBILITY OF SUCH DAMAGE. 25 | */ 26 | 27 | #ifndef DEBUG_BREAK_H 28 | #define DEBUG_BREAK_H 29 | 30 | #ifdef _MSC_VER 31 | 32 | #define debug_break __debugbreak 33 | 34 | #else 35 | 36 | #include 37 | 38 | #ifdef __cplusplus 39 | extern "C" { 40 | #endif 41 | 42 | enum { 43 | /* gcc optimizers consider code after __builtin_trap() dead. 44 | * Making __builtin_trap() unsuitable for breaking into the debugger */ 45 | DEBUG_BREAK_PREFER_BUILTIN_TRAP_TO_SIGTRAP = 0, 46 | }; 47 | 48 | #if defined(__i386__) || defined(__x86_64__) 49 | enum { HAVE_TRAP_INSTRUCTION = 1, }; 50 | __attribute__((gnu_inline, always_inline)) 51 | static void __inline__ trap_instruction(void) 52 | { 53 | __asm__ volatile("int $0x03"); 54 | } 55 | #elif defined(__thumb__) 56 | enum { HAVE_TRAP_INSTRUCTION = 1, }; 57 | /* FIXME: handle __THUMB_INTERWORK__ */ 58 | __attribute__((gnu_inline, always_inline)) 59 | static void __inline__ trap_instruction(void) 60 | { 61 | /* See 'arm-linux-tdep.c' in GDB source. 62 | * Both instruction sequences below work. */ 63 | #if 1 64 | /* 'eabi_linux_thumb_le_breakpoint' */ 65 | __asm__ volatile(".inst 0xde01"); 66 | #else 67 | /* 'eabi_linux_thumb2_le_breakpoint' */ 68 | __asm__ volatile(".inst.w 0xf7f0a000"); 69 | #endif 70 | 71 | /* Known problem: 72 | * After a breakpoint hit, can't stepi, step, or continue in GDB. 73 | * 'step' stuck on the same instruction. 74 | * 75 | * Workaround: a new GDB command, 76 | * 'debugbreak-step' is defined in debugbreak-gdb.py 77 | * that does: 78 | * (gdb) set $instruction_len = 2 79 | * (gdb) tbreak *($pc + $instruction_len) 80 | * (gdb) jump *($pc + $instruction_len) 81 | */ 82 | } 83 | #elif defined(__arm__) && !defined(__thumb__) 84 | enum { HAVE_TRAP_INSTRUCTION = 1, }; 85 | __attribute__((gnu_inline, always_inline)) 86 | static void __inline__ trap_instruction(void) 87 | { 88 | /* See 'arm-linux-tdep.c' in GDB source, 89 | * 'eabi_linux_arm_le_breakpoint' */ 90 | __asm__ volatile(".inst 0xe7f001f0"); 91 | /* Has same known problem and workaround 92 | * as Thumb mode */ 93 | } 94 | #elif defined(__aarch64__) 95 | enum { HAVE_TRAP_INSTRUCTION = 1, }; 96 | __attribute__((gnu_inline, always_inline)) 97 | static void __inline__ trap_instruction(void) 98 | { 99 | /* See 'aarch64-tdep.c' in GDB source, 100 | * 'aarch64_default_breakpoint' */ 101 | __asm__ volatile(".inst 0xd4200000"); 102 | } 103 | #else 104 | enum { HAVE_TRAP_INSTRUCTION = 0, }; 105 | #endif 106 | 107 | __attribute__((gnu_inline, always_inline)) 108 | static void __inline__ debug_break(void) 109 | { 110 | if (HAVE_TRAP_INSTRUCTION) { 111 | trap_instruction(); 112 | } else if (DEBUG_BREAK_PREFER_BUILTIN_TRAP_TO_SIGTRAP) { 113 | /* raises SIGILL on Linux x86{,-64}, to continue in gdb: 114 | * (gdb) handle SIGILL stop nopass 115 | * */ 116 | __builtin_trap(); 117 | } else { 118 | #ifdef _WIN32 119 | /* SIGTRAP available only on POSIX-compliant operating systems 120 | * use builtin trap instead */ 121 | __builtin_trap(); 122 | #else 123 | raise(SIGTRAP); 124 | #endif 125 | } 126 | } 127 | 128 | #ifdef __cplusplus 129 | } 130 | #endif 131 | 132 | #endif 133 | 134 | #endif 135 | -------------------------------------------------------------------------------- /src/dynlib/dynlib.c: -------------------------------------------------------------------------------- 1 | #include "dynlib.h" 2 | 3 | #ifdef _WIN32 4 | 5 | #include 6 | 7 | const char* dynlib_error( void ) 8 | { 9 | static char msg[ 512 ]; 10 | 11 | DWORD err = GetLastError(); 12 | 13 | DWORD res = FormatMessage( 14 | FORMAT_MESSAGE_FROM_SYSTEM, 15 | NULL, 16 | err, 17 | MAKELANGID( LANG_ENGLISH, SUBLANG_DEFAULT ), 18 | msg, 19 | sizeof( msg ) - 1, 20 | NULL 21 | ); 22 | 23 | if ( res == 0 ) 24 | { 25 | snprintf( msg, sizeof( msg ) - 1, "Error %lu", err ); 26 | msg[ sizeof( msg ) - 1 ] = 0; 27 | } 28 | 29 | return msg; 30 | } 31 | 32 | #endif 33 | -------------------------------------------------------------------------------- /src/dynlib/dynlib.h: -------------------------------------------------------------------------------- 1 | #ifndef DYNLIB_H 2 | #define DYNLIB_H 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | #ifdef _WIN32 9 | #define WIN32_LEAN_AND_MEAN 10 | #include 11 | 12 | typedef HMODULE dynlib_t; 13 | 14 | #define dynlib_open( path ) LoadLibrary( path ) 15 | #define dynlib_symbol( lib, name ) (void*)GetProcAddress( lib, name ) 16 | #define dynlib_close( lib ) FreeLibrary( lib ) 17 | 18 | const char* dynlib_error( void ); 19 | #else 20 | #include 21 | 22 | typedef void* dynlib_t; 23 | 24 | #define dynlib_open( path ) dlopen( path, RTLD_LAZY ) 25 | #define dynlib_symbol( lib, name ) dlsym( lib, name ) 26 | #define dynlib_close( lib ) dlclose( lib ) 27 | #define dynlib_error() dlerror() 28 | #endif 29 | 30 | #ifdef __cplusplus 31 | } 32 | #endif 33 | 34 | #endif /* DYNLIB_H */ 35 | -------------------------------------------------------------------------------- /src/fnkdat/fnkdat.h: -------------------------------------------------------------------------------- 1 | /* 2 | fnkdat - an interface for determining common directory names 3 | Copyright (C) 2001, 2002 David MacCormack 4 | $Header$ 5 | 6 | This program is free software; you can redistribute it and/or 7 | modify it under the terms of the GNU General Public License 8 | as published by the Free Software Foundation; either version 2 9 | of the License, or (at your option) any later version. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with this program; if not, write to the Free Software 18 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 19 | 20 | As a special exception, David MacCormack gives permission 21 | for additional uses of the text contained in the files named 22 | ``fnkdat.h'' and ``fnkdat.c'', hereafter known as FNKDAT. 23 | 24 | The exception is that, if you link the FNKDAT with other files 25 | to produce an executable, this does not by itself cause the 26 | resulting executable to be covered by the GNU General Public License. 27 | Your use of that executable is in no way restricted on account of 28 | linking the FNKDAT code into it. 29 | 30 | This exception does not however invalidate any other reasons why 31 | the executable file might be covered by the GNU General Public License. 32 | 33 | This exception applies only to the code released by David MacCormack 34 | under the name FNKDAT. If you copy code from other software into a 35 | copy of FNKDAT, as the General Public License permits, the exception does 36 | not apply to the code that you add in this way. To avoid misleading 37 | anyone as to the status of such modified files, you must delete 38 | this exception notice from them. 39 | 40 | If you write modifications of your own for FNKDAT, it is your choice 41 | whether to permit this exception to apply to your modifications. 42 | If you do not wish that, delete this exception notice. 43 | 44 | David MacCormack (djm at maccormack dot net) 45 | 46 | */ 47 | 48 | #ifndef _FNKDAT_H 49 | #define _FNKDAT_H 50 | 51 | #define FNKDAT_CONF 0x01 52 | #define FNKDAT_DATA 0x02 53 | #define FNKDAT_VAR 0x04 54 | #define FNKDAT_USER 0x08 55 | #define FNKDAT_INIT 0x10 56 | #define FNKDAT_UNINIT 0x20 57 | #define FNKDAT_CREAT 0x80 58 | 59 | /* version automatically populated */ 60 | #define FNKDAT_VERSION "0.0.8" 61 | 62 | #ifdef __cplusplus 63 | extern "C" { 64 | #endif 65 | 66 | 67 | #ifdef WIN32 68 | 69 | /* 70 | * Include UNICODE crap 71 | */ 72 | #include 73 | 74 | /* 75 | * define in a UNICODE compatible way 76 | */ 77 | int fnkdat(const _TCHAR* target, _TCHAR* buffer, int len, int flags); 78 | 79 | #else 80 | 81 | /* 82 | * basic, lovable ANSI C 83 | */ 84 | int fnkdat(const char* target, char* buffer, int len, int flags); 85 | 86 | 87 | #endif /* WIN32 */ 88 | 89 | 90 | 91 | #ifdef __cplusplus 92 | } 93 | #endif 94 | 95 | 96 | #endif /* _FNKDAT_H */ 97 | 98 | /* vi: set sw=3 ts=3 tw=78 et sts: */ 99 | 100 | -------------------------------------------------------------------------------- /src/imguiext/dirent_portable.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leiradel/CheevosHunter/a7d0145c7617caf63d42b134a831707f10c1d27b/src/imguiext/dirent_portable.h -------------------------------------------------------------------------------- /src/imguiext/imguial_button.h: -------------------------------------------------------------------------------- 1 | /* 2 | The MIT License (MIT) 3 | 4 | Copyright (c) 2016 Andre Leiradella 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in all 14 | copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | SOFTWARE. 23 | */ 24 | 25 | #pragma once 26 | 27 | namespace ImGuiAl 28 | { 29 | inline bool Button( const char* label, bool enabled = true, const ImVec2& size = ImVec2( 0, 0 ) ) 30 | { 31 | bool pressed; 32 | 33 | if ( enabled ) 34 | { 35 | pressed = ImGui::Button( label, size ); 36 | } 37 | else 38 | { 39 | static ImU32 disabled_fg = IM_COL32_BLACK; 40 | static ImU32 disabled_bg = IM_COL32( 64, 64, 64, 255 ); 41 | 42 | ImGui::PushStyleColor( ImGuiCol_Text, disabled_fg ); 43 | ImGui::PushStyleColor( ImGuiCol_Button, disabled_bg ); 44 | ImGui::PushStyleColor( ImGuiCol_ButtonHovered, disabled_bg ); 45 | ImGui::PushStyleColor( ImGuiCol_ButtonActive, disabled_bg ); 46 | ImGui::Button( label, size ); 47 | ImGui::PopStyleColor( 4 ); 48 | 49 | pressed = false; 50 | } 51 | 52 | return pressed; 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/imguiext/imguial_fonts.h: -------------------------------------------------------------------------------- 1 | /* 2 | The MIT License (MIT) 3 | 4 | Copyright (c) 2016 Andre Leiradella 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in all 14 | copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | SOFTWARE. 23 | */ 24 | 25 | #pragma once 26 | 27 | // Define these here or somewhere else to add fonts to your imgui app. 28 | //#define IMGUIAL_FONTS_COUSINE_REGULAR 29 | //#define IMGUIAL_FONTS_DROID_SANS 30 | //#define IMGUIAL_FONTS_KARLA_REGULAR 31 | //#define IMGUIAL_FONTS_PROGGY_TINY 32 | //#define IMGUIAL_FONTS_FONT_AWESOME 33 | //#define IMGUIAL_FONTS_MATERIAL_DESIGN 34 | //#define IMGUIAL_FONTS_KENNEY_ICONS 35 | 36 | #ifdef IMGUIAL_FONTS_FONT_AWESOME 37 | #include "IconsFontAwesome_c.h" 38 | #endif 39 | 40 | #ifdef IMGUIAL_FONTS_MATERIAL_DESIGN 41 | #include "IconsMaterialDesign_c.h" 42 | #endif 43 | 44 | #ifdef IMGUIAL_FONTS_KENNEY_ICONS 45 | #include "IconsKenney_c.h" 46 | #endif 47 | 48 | namespace ImGuiAl 49 | { 50 | namespace Fonts 51 | { 52 | enum Font 53 | { 54 | kCousineRegular, 55 | kDroidSans, 56 | kKarlaRegular, 57 | kProggyTiny, 58 | kFontAwesome, 59 | kMaterialDesign, 60 | kKenneyIcons 61 | }; 62 | 63 | const void* GetCompressedData( Font font, int* size ); 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /src/imguiext/imguial_log.h: -------------------------------------------------------------------------------- 1 | /* 2 | The MIT License (MIT) 3 | 4 | Copyright (c) 2016 Andre Leiradella 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in all 14 | copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | SOFTWARE. 23 | */ 24 | 25 | #pragma once 26 | 27 | #include 28 | #include 29 | #include 30 | 31 | // Must be at most 65535 32 | #ifndef IMGUIAL_LOG_MAX_LINE_SIZE 33 | #define IMGUIAL_LOG_MAX_LINE_SIZE 1024 34 | #endif 35 | 36 | // Must be at least MAX_LINE_SIZE + 3 37 | #ifndef IMGUIAL_LOG_MAX_BUFFER_SIZE 38 | #define IMGUIAL_LOG_MAX_BUFFER_SIZE 65536 39 | #endif 40 | 41 | namespace ImGuiAl 42 | { 43 | class Log 44 | { 45 | public: 46 | enum Level 47 | { 48 | kDebug = 0, 49 | kInfo = 1, 50 | kWarn = 2, 51 | kError = 3 52 | }; 53 | 54 | enum Flags 55 | { 56 | kShowFilters = 1 << 0 57 | }; 58 | 59 | typedef bool ( *IterateFunc )( Level level, const char* line, void *ud ); 60 | 61 | inline Log() 62 | { 63 | Init(); 64 | } 65 | 66 | virtual ~Log(); 67 | 68 | bool Init( unsigned flags = 0, const char** more_actions = NULL ); 69 | 70 | void SetColor( Level level, float r, float g, float b ); 71 | void SetLabel( Level level, const char* label ); 72 | void SetCumulativeLabel( const char* label ); 73 | void SetFilterHeaderLabel( const char* label ); 74 | void SetFilterLabel( const char* label ); 75 | 76 | void VPrintf( Level level, const char* format, va_list args ); 77 | 78 | void Debug( const char* format, ... ); 79 | void Info( const char* format, ... ); 80 | void Warn( const char* format, ... ); 81 | void Error( const char* format, ... ); 82 | 83 | inline void Clear() 84 | { 85 | m_First = m_Last = 0; 86 | m_Avail = IMGUIAL_LOG_MAX_BUFFER_SIZE; 87 | m_ScrollToBottom = true; 88 | } 89 | 90 | void Iterate( IterateFunc iterator, bool apply_filters, void* ud ); 91 | 92 | int Draw(); 93 | 94 | protected: 95 | void Write( const void* data, size_t size ); 96 | void Read( void* data, size_t size ); 97 | size_t Peek( size_t pos, void* data, size_t size ); 98 | 99 | inline void Skip( size_t size ) 100 | { 101 | m_First = ( m_First + size ) % IMGUIAL_LOG_MAX_BUFFER_SIZE; 102 | m_Avail += size; 103 | } 104 | 105 | char m_Buffer[ IMGUIAL_LOG_MAX_BUFFER_SIZE ]; 106 | size_t m_Avail; 107 | size_t m_First; 108 | size_t m_Last; 109 | unsigned m_Flags; 110 | const char** m_MoreActions; 111 | Level m_Level; 112 | bool m_Cumulative; 113 | ImGuiTextFilter m_Filter; 114 | bool m_ScrollToBottom; 115 | ImU32 m_Colors[ 4 ][ 4 ]; 116 | const char* m_Labels[ 4 ]; 117 | const char* m_CumulativeLabel; 118 | const char* m_FilterHeaderLabel; 119 | const char* m_FilterLabel; 120 | }; 121 | } 122 | -------------------------------------------------------------------------------- /src/imguiext/imguidock.h: -------------------------------------------------------------------------------- 1 | #ifndef IMGUIDOCK_H_ 2 | #define IMGUIDOCK_H_ 3 | 4 | // based on https://github.com/nem0/LumixEngine/blob/master/external/imgui/imgui_dock.h 5 | // Lumix Engine Dock. From: https://github.com/nem0/LumixEngine/blob/master/src/editor/imgui/imgui_dock.h 6 | /* 7 | The MIT License (MIT) 8 | 9 | Copyright (c) 2013-2016 Mikulas Florek 10 | 11 | Permission is hereby granted, free of charge, to any person obtaining a copy 12 | of this software and associated documentation files (the "Software"), to deal 13 | in the Software without restriction, including without limitation the rights 14 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 15 | copies of the Software, and to permit persons to whom the Software is 16 | furnished to do so, subject to the following conditions: 17 | 18 | The above copyright notice and this permission notice shall be included in all 19 | copies or substantial portions of the Software. 20 | 21 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 22 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 23 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 24 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 25 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 26 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 27 | SOFTWARE. 28 | */ 29 | // modified from https://bitbucket.org/duangle/liminal/src/tip/src/liminal/imgui_dock.h 30 | 31 | // USAGE: 32 | /* 33 | // Outside any ImGuiWindow: 34 | 35 | // Windowed: 36 | if (ImGui::Begin("imguidock window (= lumix engine's dock system)",NULL,ImVec2(500, 500),0.95f,ImGuiWindowFlags_NoScrollbar)) { 37 | ImGui::BeginDockspace(); 38 | static char tmp[128]; 39 | for (int i=0;i<10;i++) { 40 | sprintf(tmp,"Dock %d",i); 41 | if (i==9) ImGui::SetNextDock(ImGuiDockSlot_Bottom);// optional 42 | if(ImGui::BeginDock(tmp)) { 43 | ImGui::Text("Content of dock window %d goes here",i); 44 | } 45 | ImGui::EndDock(); 46 | } 47 | ImGui::EndDockspace(); 48 | } 49 | ImGui::End(); 50 | 51 | 52 | // Fullscreen (without visual artifacts): 53 | ImGui::SetNextWindowSize(ImGui::GetIO().DisplaySize); 54 | const ImGuiWindowFlags flags = (ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoBringToFrontOnFocus | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoSavedSettings | ImGuiWindowFlags_NoTitleBar); 55 | const float oldWindowRounding = ImGui::GetStyle().WindowRounding;ImGui::GetStyle().WindowRounding = 0; 56 | const bool visible = ImGui::Begin("imguidock window (= lumix engine's dock system)",NULL,ImVec2(0, 0),1.0f,flags); 57 | ImGui::GetStyle().WindowRounding = oldWindowRounding; 58 | if (visible) { 59 | ImGui::BeginDockspace(); 60 | static char tmp[128]; 61 | for (int i=0;i<10;i++) { 62 | sprintf(tmp,"Dock %d",i); 63 | if (i==9) ImGui::SetNextDock(ImGuiDockSlot_Bottom);// optional 64 | if(ImGui::BeginDock(tmp)) { 65 | ImGui::Text("Content of dock window %d goes here",i); 66 | } 67 | ImGui::EndDock(); 68 | } 69 | ImGui::EndDockspace(); 70 | } 71 | ImGui::End(); 72 | */ 73 | 74 | #ifndef IMGUI_API 75 | #include 76 | #endif //IMGUI_API 77 | 78 | #include "imguihelper.h" 79 | 80 | typedef enum ImGuiDockSlot { 81 | ImGuiDockSlot_Left=0, 82 | ImGuiDockSlot_Right, 83 | ImGuiDockSlot_Top, 84 | ImGuiDockSlot_Bottom, 85 | ImGuiDockSlot_Tab, 86 | 87 | ImGuiDockSlot_Float, 88 | ImGuiDockSlot_None 89 | } ImGuiDockSlot; 90 | 91 | namespace ImGui{ 92 | 93 | IMGUI_API void BeginDockspace(); 94 | IMGUI_API void EndDockspace(); 95 | IMGUI_API void ShutdownDock(); 96 | IMGUI_API void SetNextDock(ImGuiDockSlot slot); 97 | IMGUI_API bool BeginDock(const char* label, bool* opened = NULL, ImGuiWindowFlags extra_flags = 0, const ImVec2& default_size = ImVec2(-1, -1)); 98 | IMGUI_API void EndDock(); 99 | IMGUI_API void SetDockActive(); 100 | IMGUI_API void DockDebugWindow(); 101 | 102 | // Ported from the original "Lua binding" code 103 | #if (defined(IMGUIHELPER_H_) && !defined(NO_IMGUIHELPER_SERIALIZATION)) 104 | # ifndef NO_IMGUIHELPER_SERIALIZATION_SAVE 105 | IMGUI_API bool SaveDock(ImGuiHelper::Serializer& s); 106 | IMGUI_API bool SaveDock(const char* filename); 107 | # endif //NO_IMGUIHELPER_SERIALIZATION_SAVE 108 | # ifndef NO_IMGUIHELPER_SERIALIZATION_LOAD 109 | IMGUI_API bool LoadDock(ImGuiHelper::Deserializer& d,const char ** pOptionalBufferStart=NULL); 110 | IMGUI_API bool LoadDock(const char* filename); 111 | # endif //NO_IMGUIHELPER_SERIALIZATION_LOAD 112 | #endif //(defined(IMGUIHELPER_H_) && !defined(NO_IMGUIHELPER_SERIALIZATION)) 113 | 114 | } // namespace ImGui 115 | 116 | extern bool gImGuiDockReuseTabWindowTextureIfAvailable; // [true] (used only when available) 117 | 118 | 119 | #endif //IMGUIDOCK_H_ 120 | 121 | -------------------------------------------------------------------------------- /src/libretro/Components.h: -------------------------------------------------------------------------------- 1 | /* 2 | The MIT License (MIT) 3 | 4 | Copyright (c) 2016 Andre Leiradella 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in all 14 | copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | SOFTWARE. 23 | */ 24 | 25 | #pragma once 26 | 27 | /** 28 | * Include cstdarg for va_list usage. 29 | */ 30 | #include 31 | 32 | #include "libretropp.h" 33 | 34 | namespace libretro { 35 | /** 36 | * A logger component for Core instances. 37 | */ 38 | class LoggerComponent { 39 | public: 40 | virtual void vprintf(enum retro_log_level level, const char* fmt, va_list args) = 0; 41 | 42 | inline void printf(enum retro_log_level level, const char* fmt, ...) { 43 | va_list args; 44 | va_start(args, fmt); 45 | vprintf(level, fmt, args); 46 | va_end(args); 47 | } 48 | }; 49 | 50 | /** 51 | * A component that returns configuration values for CoreWrap instances. 52 | */ 53 | class ConfigComponent { 54 | public: 55 | virtual std::string const& getCoreAssetsDirectory() = 0; 56 | virtual std::string const& getSaveDirectory() = 0; 57 | virtual std::string const& getSystemPath() = 0; 58 | 59 | virtual void setVariables(std::vector const& variables) = 0; 60 | virtual bool varUpdated() = 0; 61 | virtual std::string const& getVariable(std::string const& variable) = 0; 62 | }; 63 | 64 | /** 65 | * A Video component. 66 | */ 67 | class VideoComponent { 68 | public: 69 | virtual bool setGeometry(unsigned width, unsigned height, float aspect, enum retro_pixel_format pixelFormat) = 0; 70 | virtual void refresh(const void* data, unsigned width, unsigned height, size_t pitch) = 0; 71 | 72 | virtual uintptr_t getCurrentFramebuffer() = 0; 73 | 74 | virtual void showMessage(std::string const& msg, unsigned frames) = 0; 75 | }; 76 | 77 | /** 78 | * An audio component. 79 | */ 80 | class AudioComponent { 81 | public: 82 | virtual bool setRate(double rate) = 0; 83 | virtual void mix(const int16_t* samples, size_t frames) = 0; 84 | }; 85 | 86 | /** 87 | * A component that provides input state to CoreWrap instances. 88 | */ 89 | class InputComponent { 90 | public: 91 | virtual void setInputDescriptors(std::vector const& descs) = 0; 92 | 93 | virtual void setControllerInfo(std::vector const& info) = 0; 94 | virtual bool ctrlUpdated() = 0; 95 | virtual unsigned getController(unsigned port) = 0; 96 | 97 | virtual void poll() = 0; 98 | virtual int16_t read(unsigned port, unsigned device, unsigned index, unsigned id) = 0; 99 | }; 100 | 101 | /** 102 | * A component responsible for loading content from the file system. 103 | */ 104 | class LoaderComponent { 105 | public: 106 | virtual void* load(size_t* size, std::string const& path) = 0; 107 | virtual void free(void* data) = 0; 108 | }; 109 | } 110 | -------------------------------------------------------------------------------- /src/libretro/Core.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | The MIT License (MIT) 3 | 4 | Copyright (c) 2016 Andre Leiradella 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in all 14 | copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | SOFTWARE. 23 | */ 24 | 25 | #include "Core.h" 26 | 27 | #include 28 | #include 29 | #include 30 | #include 31 | 32 | #define CORE_DLSYM(prop, name) \ 33 | do { \ 34 | void* sym = dynlib_symbol(_handle, name); \ 35 | if (!sym) goto error; \ 36 | memcpy(&prop, &sym, sizeof(prop)); \ 37 | } while (0) 38 | 39 | bool libretro::Core::load(std::string const& path, std::string* const error) { 40 | _handle = dynlib_open(path.c_str()); 41 | 42 | if (_handle == NULL) { 43 | if (error != nullptr) { 44 | *error = dynlib_error(); 45 | } 46 | 47 | return false; 48 | } 49 | 50 | CORE_DLSYM(_init, "retro_init"); 51 | CORE_DLSYM(_deinit, "retro_deinit"); 52 | CORE_DLSYM(_apiVersion, "retro_api_version"); 53 | CORE_DLSYM(_getSystemInfo, "retro_get_system_info"); 54 | CORE_DLSYM(_getSystemAVInfo, "retro_get_system_av_info"); 55 | CORE_DLSYM(_setEnvironment, "retro_set_environment"); 56 | CORE_DLSYM(_setVideoRefresh, "retro_set_video_refresh"); 57 | CORE_DLSYM(_setAudioSample, "retro_set_audio_sample"); 58 | CORE_DLSYM(_setAudioSampleBatch, "retro_set_audio_sample_batch"); 59 | CORE_DLSYM(_setInputPoll, "retro_set_input_poll"); 60 | CORE_DLSYM(_setInputState, "retro_set_input_state"); 61 | CORE_DLSYM(_setControllerPortDevice, "retro_set_controller_port_device"); 62 | CORE_DLSYM(_reset, "retro_reset"); 63 | CORE_DLSYM(_run, "retro_run"); 64 | CORE_DLSYM(_serializeSize, "retro_serialize_size"); 65 | CORE_DLSYM(_serialize, "retro_serialize"); 66 | CORE_DLSYM(_unserialize, "retro_unserialize"); 67 | CORE_DLSYM(_cheatReset, "retro_cheat_reset"); 68 | CORE_DLSYM(_cheatSet, "retro_cheat_set"); 69 | CORE_DLSYM(_loadGame, "retro_load_game"); 70 | CORE_DLSYM(_loadGameSpecial, "retro_load_game_special"); 71 | CORE_DLSYM(_unloadGame, "retro_unload_game"); 72 | CORE_DLSYM(_getRegion, "retro_get_region"); 73 | CORE_DLSYM(_getMemoryData, "retro_get_memory_data"); 74 | CORE_DLSYM(_getMemorySize, "retro_get_memory_size"); 75 | 76 | return true; 77 | 78 | error: 79 | if (error != nullptr) { 80 | *error = dynlib_error(); 81 | } 82 | 83 | dynlib_close(_handle); 84 | return false; 85 | } 86 | 87 | #undef CORE_DLSYM 88 | 89 | void libretro::Core::destroy() { 90 | dynlib_close(_handle); 91 | } 92 | -------------------------------------------------------------------------------- /src/libretro/Core.h: -------------------------------------------------------------------------------- 1 | /* 2 | The MIT License (MIT) 3 | 4 | Copyright (c) 2016 Andre Leiradella 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in all 14 | copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | SOFTWARE. 23 | */ 24 | 25 | #pragma once 26 | 27 | #include "libretro.h" 28 | #include "dynlib/dynlib.h" 29 | 30 | #include 31 | 32 | namespace libretro { 33 | /** 34 | * Core represents a libretro core loaded from the file system, i.e. 35 | * stella_libretro.so. Its methods map 1:1 to the ones from the libretro 36 | * API, not couting load, that loads a core, and destroy, which unloads the 37 | * core and destroys the object. 38 | * 39 | * It's the caller's responsibility to ensure that the core is always in a 40 | * consistent state. 41 | */ 42 | class Core { 43 | public: 44 | // Loads a core specified by its file path. 45 | bool load(std::string const& path, std::string* const error); 46 | 47 | // Unloads the core from memory. 48 | void destroy(); 49 | 50 | // All the remaining methods map 1:1 to the libretro API. 51 | void init() const { _init(); } 52 | void deinit() const { _deinit(); } 53 | unsigned apiVersion() const { return _apiVersion(); } 54 | void getSystemInfo(struct retro_system_info* info) const { _getSystemInfo(info); } 55 | void getSystemAVInfo(struct retro_system_av_info* info) const { _getSystemAVInfo(info); } 56 | void setEnvironment(retro_environment_t cb) const { _setEnvironment(cb); } 57 | void setVideoRefresh(retro_video_refresh_t cb) const { _setVideoRefresh(cb); } 58 | void setAudioSample(retro_audio_sample_t cb) const { _setAudioSample(cb); } 59 | void setAudioSampleBatch(retro_audio_sample_batch_t cb) const { _setAudioSampleBatch(cb); } 60 | void setInputPoll(retro_input_poll_t cb) const { _setInputPoll(cb); } 61 | void setInputState(retro_input_state_t cb) const { _setInputState(cb); } 62 | void setControllerPortDevice(unsigned port, unsigned device) const { _setControllerPortDevice(port, device); } 63 | void reset() const { _reset(); } 64 | void run() const { _run(); } 65 | size_t serializeSize() const { return _serializeSize(); } 66 | bool serialize(void* data, size_t size) const { return _serialize(data, size); } 67 | bool unserialize(const void* data, size_t size) const { return _unserialize(data, size); } 68 | void cheatReset() const { return _cheatReset(); } 69 | void cheatSet(unsigned index, bool enabled, const char* code) const { _cheatSet(index, enabled, code); } 70 | bool loadGame(const struct retro_game_info* game) const { return _loadGame(game); } 71 | 72 | bool loadGameSpecial(unsigned game_type, const struct retro_game_info* info, size_t num_info) const { 73 | return _loadGameSpecial(game_type, info, num_info); 74 | } 75 | 76 | void unloadGame() const { _unloadGame(); } 77 | unsigned getRegion() const { return _getRegion(); } 78 | void* getMemoryData(unsigned id) const { return _getMemoryData(id); } 79 | size_t getMemorySize(unsigned id) const { return _getMemorySize(id); } 80 | 81 | protected: 82 | dynlib_t _handle; 83 | 84 | void (*_init)(); 85 | void (*_deinit)(); 86 | unsigned (*_apiVersion)(); 87 | void (*_getSystemInfo)(struct retro_system_info*); 88 | void (*_getSystemAVInfo)(struct retro_system_av_info*); 89 | void (*_setEnvironment)(retro_environment_t); 90 | void (*_setVideoRefresh)(retro_video_refresh_t); 91 | void (*_setAudioSample)(retro_audio_sample_t); 92 | void (*_setAudioSampleBatch)(retro_audio_sample_batch_t); 93 | void (*_setInputPoll)(retro_input_poll_t); 94 | void (*_setInputState)(retro_input_state_t); 95 | void (*_setControllerPortDevice)(unsigned, unsigned); 96 | void (*_reset)(); 97 | void (*_run)(); 98 | size_t (*_serializeSize)(); 99 | bool (*_serialize)(void*, size_t); 100 | bool (*_unserialize)(const void*, size_t); 101 | void (*_cheatReset)(); 102 | void (*_cheatSet)(unsigned, bool, const char*); 103 | bool (*_loadGame)(const struct retro_game_info*); 104 | bool (*_loadGameSpecial)(unsigned, const struct retro_game_info*, size_t); 105 | void (*_unloadGame)(); 106 | unsigned (*_getRegion)(); 107 | void* (*_getMemoryData)(unsigned); 108 | size_t (*_getMemorySize)(unsigned); 109 | }; 110 | } 111 | -------------------------------------------------------------------------------- /src/libretro/libretropp.h: -------------------------------------------------------------------------------- 1 | /* 2 | The MIT License (MIT) 3 | 4 | Copyright (c) 2016 Andre Leiradella 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in all 14 | copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | SOFTWARE. 23 | */ 24 | 25 | #pragma once 26 | 27 | #include "libretro.h" 28 | #include 29 | #include 30 | 31 | namespace libretro { 32 | struct InputDescriptor { 33 | unsigned port; 34 | unsigned device; 35 | unsigned index; 36 | unsigned id; 37 | std::string description; 38 | }; 39 | 40 | struct Variable { 41 | std::string key; 42 | std::string value; 43 | }; 44 | 45 | struct SubsystemInfo { 46 | struct RomInfo { 47 | struct MemoryInfo { 48 | std::string extension; 49 | unsigned type; 50 | }; 51 | 52 | std::string desc; 53 | std::string validExtensions; 54 | bool needFullpath; 55 | bool blockExtract; 56 | bool required; 57 | 58 | std::vector memory; 59 | }; 60 | 61 | std::string desc; 62 | std::string ident; 63 | std::vector roms; 64 | unsigned id; 65 | }; 66 | 67 | struct ControllerDescription { 68 | std::string desc; 69 | unsigned id; 70 | }; 71 | 72 | struct ControllerInfo { 73 | std::vector types; 74 | }; 75 | 76 | struct SystemInfo { 77 | std::string libraryName; 78 | std::string libraryVersion; 79 | std::string validExtensions; 80 | bool needFullpath; 81 | bool blockExtract; 82 | }; 83 | 84 | struct SystemAVInfo { 85 | struct Geometry { 86 | unsigned baseWidth; 87 | unsigned baseHeight; 88 | unsigned maxWidth; 89 | unsigned maxHeight; 90 | float aspectRatio; 91 | }; 92 | 93 | struct Timing { 94 | double fps; 95 | double sampleRate; 96 | }; 97 | 98 | Geometry geometry; 99 | Timing timing; 100 | }; 101 | 102 | struct MemoryDescriptor { 103 | uint64_t flags; 104 | void *ptr; 105 | size_t offset; 106 | size_t start; 107 | size_t select; 108 | size_t disconnect; 109 | size_t len; 110 | std::string addrspace; 111 | }; 112 | } 113 | -------------------------------------------------------------------------------- /src/lua-5.3.5/Makefile: -------------------------------------------------------------------------------- 1 | # Makefile for installing Lua 2 | # See doc/readme.html for installation and customization instructions. 3 | 4 | # == CHANGE THE SETTINGS BELOW TO SUIT YOUR ENVIRONMENT ======================= 5 | 6 | # Your platform. See PLATS for possible values. 7 | PLAT= none 8 | 9 | # Where to install. The installation starts in the src and doc directories, 10 | # so take care if INSTALL_TOP is not an absolute path. See the local target. 11 | # You may want to make INSTALL_LMOD and INSTALL_CMOD consistent with 12 | # LUA_ROOT, LUA_LDIR, and LUA_CDIR in luaconf.h. 13 | INSTALL_TOP= /usr/local 14 | INSTALL_BIN= $(INSTALL_TOP)/bin 15 | INSTALL_INC= $(INSTALL_TOP)/include 16 | INSTALL_LIB= $(INSTALL_TOP)/lib 17 | INSTALL_MAN= $(INSTALL_TOP)/man/man1 18 | INSTALL_LMOD= $(INSTALL_TOP)/share/lua/$V 19 | INSTALL_CMOD= $(INSTALL_TOP)/lib/lua/$V 20 | 21 | # How to install. If your install program does not support "-p", then 22 | # you may have to run ranlib on the installed liblua.a. 23 | INSTALL= install -p 24 | INSTALL_EXEC= $(INSTALL) -m 0755 25 | INSTALL_DATA= $(INSTALL) -m 0644 26 | # 27 | # If you don't have "install" you can use "cp" instead. 28 | # INSTALL= cp -p 29 | # INSTALL_EXEC= $(INSTALL) 30 | # INSTALL_DATA= $(INSTALL) 31 | 32 | # Other utilities. 33 | MKDIR= mkdir -p 34 | RM= rm -f 35 | 36 | # == END OF USER SETTINGS -- NO NEED TO CHANGE ANYTHING BELOW THIS LINE ======= 37 | 38 | # Convenience platforms targets. 39 | PLATS= aix bsd c89 freebsd generic linux macosx mingw posix solaris 40 | 41 | # What to install. 42 | TO_BIN= lua luac 43 | TO_INC= lua.h luaconf.h lualib.h lauxlib.h lua.hpp 44 | TO_LIB= liblua.a 45 | TO_MAN= lua.1 luac.1 46 | 47 | # Lua version and release. 48 | V= 5.3 49 | R= $V.4 50 | 51 | # Targets start here. 52 | all: $(PLAT) 53 | 54 | $(PLATS) clean: 55 | cd src && $(MAKE) $@ 56 | 57 | test: dummy 58 | src/lua -v 59 | 60 | install: dummy 61 | cd src && $(MKDIR) $(INSTALL_BIN) $(INSTALL_INC) $(INSTALL_LIB) $(INSTALL_MAN) $(INSTALL_LMOD) $(INSTALL_CMOD) 62 | cd src && $(INSTALL_EXEC) $(TO_BIN) $(INSTALL_BIN) 63 | cd src && $(INSTALL_DATA) $(TO_INC) $(INSTALL_INC) 64 | cd src && $(INSTALL_DATA) $(TO_LIB) $(INSTALL_LIB) 65 | cd doc && $(INSTALL_DATA) $(TO_MAN) $(INSTALL_MAN) 66 | 67 | uninstall: 68 | cd src && cd $(INSTALL_BIN) && $(RM) $(TO_BIN) 69 | cd src && cd $(INSTALL_INC) && $(RM) $(TO_INC) 70 | cd src && cd $(INSTALL_LIB) && $(RM) $(TO_LIB) 71 | cd doc && cd $(INSTALL_MAN) && $(RM) $(TO_MAN) 72 | 73 | local: 74 | $(MAKE) install INSTALL_TOP=../install 75 | 76 | none: 77 | @echo "Please do 'make PLATFORM' where PLATFORM is one of these:" 78 | @echo " $(PLATS)" 79 | @echo "See doc/readme.html for complete instructions." 80 | 81 | # make may get confused with test/ and install/ 82 | dummy: 83 | 84 | # echo config parameters 85 | echo: 86 | @cd src && $(MAKE) -s echo 87 | @echo "PLAT= $(PLAT)" 88 | @echo "V= $V" 89 | @echo "R= $R" 90 | @echo "TO_BIN= $(TO_BIN)" 91 | @echo "TO_INC= $(TO_INC)" 92 | @echo "TO_LIB= $(TO_LIB)" 93 | @echo "TO_MAN= $(TO_MAN)" 94 | @echo "INSTALL_TOP= $(INSTALL_TOP)" 95 | @echo "INSTALL_BIN= $(INSTALL_BIN)" 96 | @echo "INSTALL_INC= $(INSTALL_INC)" 97 | @echo "INSTALL_LIB= $(INSTALL_LIB)" 98 | @echo "INSTALL_MAN= $(INSTALL_MAN)" 99 | @echo "INSTALL_LMOD= $(INSTALL_LMOD)" 100 | @echo "INSTALL_CMOD= $(INSTALL_CMOD)" 101 | @echo "INSTALL_EXEC= $(INSTALL_EXEC)" 102 | @echo "INSTALL_DATA= $(INSTALL_DATA)" 103 | 104 | # echo pkg-config data 105 | pc: 106 | @echo "version=$R" 107 | @echo "prefix=$(INSTALL_TOP)" 108 | @echo "libdir=$(INSTALL_LIB)" 109 | @echo "includedir=$(INSTALL_INC)" 110 | 111 | # list targets that do not create files (but not all makes understand .PHONY) 112 | .PHONY: all $(PLATS) clean test install local none dummy echo pecho lecho 113 | 114 | # (end of Makefile) 115 | -------------------------------------------------------------------------------- /src/lua-5.3.5/README: -------------------------------------------------------------------------------- 1 | 2 | This is Lua 5.3.5, released on 26 Jun 2018. 3 | 4 | For installation instructions, license details, and 5 | further information about Lua, see doc/readme.html. 6 | 7 | -------------------------------------------------------------------------------- /src/lua-5.3.5/doc/index.css: -------------------------------------------------------------------------------- 1 | ul { 2 | list-style-type: none ; 3 | } 4 | 5 | ul.contents { 6 | padding: 0 ; 7 | } 8 | 9 | table { 10 | border: none ; 11 | border-spacing: 0 ; 12 | border-collapse: collapse ; 13 | } 14 | 15 | td { 16 | vertical-align: top ; 17 | padding: 0 ; 18 | text-align: left ; 19 | line-height: 1.25 ; 20 | width: 15% ; 21 | } 22 | -------------------------------------------------------------------------------- /src/lua-5.3.5/doc/logo.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leiradel/CheevosHunter/a7d0145c7617caf63d42b134a831707f10c1d27b/src/lua-5.3.5/doc/logo.gif -------------------------------------------------------------------------------- /src/lua-5.3.5/doc/lua.1: -------------------------------------------------------------------------------- 1 | .\" $Id: lua.man,v 1.14 2016/10/17 15:43:50 lhf Exp $ 2 | .TH LUA 1 "$Date: 2016/10/17 15:43:50 $" 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 standalone 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 | are handled in order and then 31 | the Lua program in file 32 | .I script 33 | is loaded and executed. 34 | The given 35 | .I args 36 | are available to 37 | .I script 38 | as strings in a global table named 39 | .BR arg . 40 | If no options or arguments are given, 41 | then 42 | .B "\-v \-i" 43 | is assumed when the standard input is a terminal; 44 | otherwise, 45 | .B "\-" 46 | is assumed. 47 | .LP 48 | In interactive mode, 49 | .B lua 50 | prompts the user, 51 | reads lines from the standard input, 52 | and executes them as they are read. 53 | If the line contains an expression or list of expressions, 54 | then the line is evaluated and the results are printed. 55 | If a line does not contain a complete statement, 56 | then a secondary prompt is displayed and 57 | lines are read until a complete statement is formed or 58 | a syntax error is found. 59 | .LP 60 | At the very start, 61 | before even handling the command line, 62 | .B lua 63 | checks the contents of the environment variables 64 | .B LUA_INIT_5_3 65 | or 66 | .BR LUA_INIT , 67 | in that order. 68 | If the contents is of the form 69 | .RI '@ filename ', 70 | then 71 | .I filename 72 | is executed. 73 | Otherwise, the string is assumed to be a Lua statement and is executed. 74 | .SH OPTIONS 75 | .TP 76 | .BI \-e " stat" 77 | execute statement 78 | .IR stat . 79 | .TP 80 | .B \-i 81 | enter interactive mode after executing 82 | .IR script . 83 | .TP 84 | .BI \-l " name" 85 | execute the equivalent of 86 | .IB name =require(' name ') 87 | before executing 88 | .IR script . 89 | .TP 90 | .B \-v 91 | show version information. 92 | .TP 93 | .B \-E 94 | ignore environment variables. 95 | .TP 96 | .B \-\- 97 | stop handling options. 98 | .TP 99 | .B \- 100 | stop handling options and execute the standard input as a file. 101 | .SH "SEE ALSO" 102 | .BR luac (1) 103 | .br 104 | The documentation at lua.org, 105 | especially section 7 of the reference manual. 106 | .SH DIAGNOSTICS 107 | Error messages should be self explanatory. 108 | .SH AUTHORS 109 | R. Ierusalimschy, 110 | L. H. de Figueiredo, 111 | W. Celes 112 | .\" EOF 113 | -------------------------------------------------------------------------------- /src/lua-5.3.5/doc/lua.css: -------------------------------------------------------------------------------- 1 | html { 2 | background-color: #F8F8F8 ; 3 | } 4 | 5 | body { 6 | background-color: #FFFFFF ; 7 | color: #000000 ; 8 | font-family: Helvetica, Arial, sans-serif ; 9 | text-align: justify ; 10 | line-height: 1.25 ; 11 | margin: 16px auto ; 12 | padding: 32px ; 13 | border: solid #ccc 1px ; 14 | border-radius: 20px ; 15 | max-width: 70em ; 16 | width: 90% ; 17 | } 18 | 19 | h1, h2, h3, h4 { 20 | color: #000080 ; 21 | font-family: Verdana, Geneva, sans-serif ; 22 | font-weight: normal ; 23 | font-style: normal ; 24 | text-align: left ; 25 | } 26 | 27 | h1 { 28 | font-size: 28pt ; 29 | } 30 | 31 | h1 img { 32 | vertical-align: text-bottom ; 33 | } 34 | 35 | h2:before { 36 | content: "\2756" ; 37 | padding-right: 0.5em ; 38 | } 39 | 40 | a { 41 | text-decoration: none ; 42 | } 43 | 44 | a:link { 45 | color: #000080 ; 46 | } 47 | 48 | a:link:hover, a:visited:hover { 49 | background-color: #D0D0FF ; 50 | color: #000080 ; 51 | border-radius: 4px ; 52 | } 53 | 54 | a:link:active, a:visited:active { 55 | color: #FF0000 ; 56 | } 57 | 58 | div.menubar { 59 | padding-bottom: 0.5em ; 60 | } 61 | 62 | p.menubar { 63 | margin-left: 2.5em ; 64 | } 65 | 66 | .menubar a:hover { 67 | margin: -3px -3px -3px -3px ; 68 | padding: 3px 3px 3px 3px ; 69 | border-radius: 4px ; 70 | } 71 | 72 | :target { 73 | background-color: #F0F0F0 ; 74 | margin: -8px ; 75 | padding: 8px ; 76 | border-radius: 8px ; 77 | outline: none ; 78 | } 79 | 80 | hr { 81 | display: none ; 82 | } 83 | 84 | table hr { 85 | background-color: #a0a0a0 ; 86 | color: #a0a0a0 ; 87 | border: 0 ; 88 | height: 1px ; 89 | display: block ; 90 | } 91 | 92 | .footer { 93 | color: gray ; 94 | font-size: x-small ; 95 | text-transform: lowercase ; 96 | } 97 | 98 | input[type=text] { 99 | border: solid #a0a0a0 2px ; 100 | border-radius: 2em ; 101 | background-image: url('images/search.png') ; 102 | background-repeat: no-repeat ; 103 | background-position: 4px center ; 104 | padding-left: 20px ; 105 | height: 2em ; 106 | } 107 | 108 | pre.session { 109 | background-color: #F8F8F8 ; 110 | padding: 1em ; 111 | border-radius: 8px ; 112 | } 113 | 114 | table { 115 | border: none ; 116 | border-spacing: 0 ; 117 | border-collapse: collapse ; 118 | } 119 | 120 | td { 121 | padding: 0 ; 122 | margin: 0 ; 123 | } 124 | 125 | td.gutter { 126 | width: 4% ; 127 | } 128 | 129 | table.columns td { 130 | vertical-align: top ; 131 | padding-bottom: 1em ; 132 | text-align: justify ; 133 | line-height: 1.25 ; 134 | } 135 | 136 | table.book td { 137 | vertical-align: top ; 138 | } 139 | 140 | table.book td.cover { 141 | padding-right: 1em ; 142 | } 143 | 144 | table.book img { 145 | border: solid #000080 1px ; 146 | } 147 | 148 | table.book span { 149 | font-size: small ; 150 | text-align: left ; 151 | display: block ; 152 | margin-top: 0.25em ; 153 | } 154 | 155 | p.logos a:link:hover, p.logos a:visited:hover { 156 | background-color: inherit ; 157 | } 158 | 159 | img { 160 | background-color: white ; 161 | } 162 | -------------------------------------------------------------------------------- /src/lua-5.3.5/doc/luac.1: -------------------------------------------------------------------------------- 1 | .\" $Id: luac.man,v 1.29 2011/11/16 13:53:40 lhf Exp $ 2 | .TH LUAC 1 "$Date: 2011/11/16 13:53:40 $" 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 containing precompiled chunks 17 | that can be later loaded and executed. 18 | .LP 19 | The main advantages of precompiling chunks are: 20 | faster loading, 21 | protecting source code from accidental user changes, 22 | and 23 | off-line syntax checking. 24 | Precompiling 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 | Precompiled chunks are not necessarily smaller than the corresponding source. 29 | The main goal in precompiling is faster loading. 30 | .LP 31 | In the command line, 32 | you can mix 33 | text files containing Lua source and 34 | binary files containing precompiled chunks. 35 | .B luac 36 | produces a single output file containing the combined bytecodes 37 | for all files given. 38 | Executing the combined file is equivalent to executing the given files. 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 | Precompiled chunks are 47 | .I not 48 | portable across different architectures. 49 | Moreover, 50 | the internal format of precompiled chunks 51 | is likely to change when a new version of Lua is released. 52 | Make sure you save the source files of all Lua programs that you precompile. 53 | .LP 54 | .SH OPTIONS 55 | .TP 56 | .B \-l 57 | produce a listing of the compiled bytecode for Lua's virtual machine. 58 | Listing bytecodes is useful to learn about Lua's virtual machine. 59 | If no files are given, then 60 | .B luac 61 | loads 62 | .B luac.out 63 | and lists its contents. 64 | Use 65 | .B \-l \-l 66 | for a full listing. 67 | .TP 68 | .BI \-o " file" 69 | output to 70 | .IR file , 71 | instead of the default 72 | .BR luac.out . 73 | (You can use 74 | .B "'\-'" 75 | for standard output, 76 | but not on platforms that open standard output in text mode.) 77 | The output file may be one of the given files because 78 | all files are loaded before the output file is written. 79 | Be careful not to overwrite precious files. 80 | .TP 81 | .B \-p 82 | load files but do not generate any output file. 83 | Used mainly for syntax checking and for testing precompiled chunks: 84 | corrupted files will probably generate errors when loaded. 85 | If no files are given, then 86 | .B luac 87 | loads 88 | .B luac.out 89 | and tests its contents. 90 | No messages are displayed if the file loads without errors. 91 | .TP 92 | .B \-s 93 | strip debug information before writing the output file. 94 | This saves some space in very large chunks, 95 | but if errors occur when running a stripped chunk, 96 | then the error messages may not contain the full information they usually do. 97 | In particular, 98 | line numbers and names of local variables are lost. 99 | .TP 100 | .B \-v 101 | show version information. 102 | .TP 103 | .B \-\- 104 | stop handling options. 105 | .TP 106 | .B \- 107 | stop handling options and process standard input. 108 | .SH "SEE ALSO" 109 | .BR lua (1) 110 | .br 111 | The documentation at lua.org. 112 | .SH DIAGNOSTICS 113 | Error messages should be self explanatory. 114 | .SH AUTHORS 115 | R. Ierusalimschy, 116 | L. H. de Figueiredo, 117 | W. Celes 118 | .\" EOF 119 | -------------------------------------------------------------------------------- /src/lua-5.3.5/doc/manual.css: -------------------------------------------------------------------------------- 1 | h3 code { 2 | font-family: inherit ; 3 | font-size: inherit ; 4 | } 5 | 6 | pre, code { 7 | font-size: 12pt ; 8 | } 9 | 10 | span.apii { 11 | color: gray ; 12 | float: right ; 13 | font-family: inherit ; 14 | font-style: normal ; 15 | font-size: small ; 16 | } 17 | 18 | h2:before { 19 | content: "" ; 20 | padding-right: 0em ; 21 | } 22 | -------------------------------------------------------------------------------- /src/lua-5.3.5/doc/osi-certified-72x60.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leiradel/CheevosHunter/a7d0145c7617caf63d42b134a831707f10c1d27b/src/lua-5.3.5/doc/osi-certified-72x60.png -------------------------------------------------------------------------------- /src/lua-5.3.5/src/lapi.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lapi.h,v 2.9.1.1 2017/04/19 17:20:42 roberto Exp $ 3 | ** Auxiliary functions from Lua API 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef lapi_h 8 | #define lapi_h 9 | 10 | 11 | #include "llimits.h" 12 | #include "lstate.h" 13 | 14 | #define api_incr_top(L) {L->top++; api_check(L, L->top <= L->ci->top, \ 15 | "stack overflow");} 16 | 17 | #define adjustresults(L,nres) \ 18 | { if ((nres) == LUA_MULTRET && L->ci->top < L->top) L->ci->top = L->top; } 19 | 20 | #define api_checknelems(L,n) api_check(L, (n) < (L->top - L->ci->func), \ 21 | "not enough elements in the stack") 22 | 23 | 24 | #endif 25 | -------------------------------------------------------------------------------- /src/lua-5.3.5/src/lbitlib.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lbitlib.c,v 1.30.1.1 2017/04/19 17:20:42 roberto Exp $ 3 | ** Standard library for bitwise operations 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #define lbitlib_c 8 | #define LUA_LIB 9 | 10 | #include "lprefix.h" 11 | 12 | 13 | #include "lua.h" 14 | 15 | #include "lauxlib.h" 16 | #include "lualib.h" 17 | 18 | 19 | #if defined(LUA_COMPAT_BITLIB) /* { */ 20 | 21 | 22 | #define pushunsigned(L,n) lua_pushinteger(L, (lua_Integer)(n)) 23 | #define checkunsigned(L,i) ((lua_Unsigned)luaL_checkinteger(L,i)) 24 | 25 | 26 | /* number of bits to consider in a number */ 27 | #if !defined(LUA_NBITS) 28 | #define LUA_NBITS 32 29 | #endif 30 | 31 | 32 | /* 33 | ** a lua_Unsigned with its first LUA_NBITS bits equal to 1. (Shift must 34 | ** be made in two parts to avoid problems when LUA_NBITS is equal to the 35 | ** number of bits in a lua_Unsigned.) 36 | */ 37 | #define ALLONES (~(((~(lua_Unsigned)0) << (LUA_NBITS - 1)) << 1)) 38 | 39 | 40 | /* macro to trim extra bits */ 41 | #define trim(x) ((x) & ALLONES) 42 | 43 | 44 | /* builds a number with 'n' ones (1 <= n <= LUA_NBITS) */ 45 | #define mask(n) (~((ALLONES << 1) << ((n) - 1))) 46 | 47 | 48 | 49 | static lua_Unsigned andaux (lua_State *L) { 50 | int i, n = lua_gettop(L); 51 | lua_Unsigned r = ~(lua_Unsigned)0; 52 | for (i = 1; i <= n; i++) 53 | r &= checkunsigned(L, i); 54 | return trim(r); 55 | } 56 | 57 | 58 | static int b_and (lua_State *L) { 59 | lua_Unsigned r = andaux(L); 60 | pushunsigned(L, r); 61 | return 1; 62 | } 63 | 64 | 65 | static int b_test (lua_State *L) { 66 | lua_Unsigned r = andaux(L); 67 | lua_pushboolean(L, r != 0); 68 | return 1; 69 | } 70 | 71 | 72 | static int b_or (lua_State *L) { 73 | int i, n = lua_gettop(L); 74 | lua_Unsigned r = 0; 75 | for (i = 1; i <= n; i++) 76 | r |= checkunsigned(L, i); 77 | pushunsigned(L, trim(r)); 78 | return 1; 79 | } 80 | 81 | 82 | static int b_xor (lua_State *L) { 83 | int i, n = lua_gettop(L); 84 | lua_Unsigned r = 0; 85 | for (i = 1; i <= n; i++) 86 | r ^= checkunsigned(L, i); 87 | pushunsigned(L, trim(r)); 88 | return 1; 89 | } 90 | 91 | 92 | static int b_not (lua_State *L) { 93 | lua_Unsigned r = ~checkunsigned(L, 1); 94 | pushunsigned(L, trim(r)); 95 | return 1; 96 | } 97 | 98 | 99 | static int b_shift (lua_State *L, lua_Unsigned r, lua_Integer i) { 100 | if (i < 0) { /* shift right? */ 101 | i = -i; 102 | r = trim(r); 103 | if (i >= LUA_NBITS) r = 0; 104 | else r >>= i; 105 | } 106 | else { /* shift left */ 107 | if (i >= LUA_NBITS) r = 0; 108 | else r <<= i; 109 | r = trim(r); 110 | } 111 | pushunsigned(L, r); 112 | return 1; 113 | } 114 | 115 | 116 | static int b_lshift (lua_State *L) { 117 | return b_shift(L, checkunsigned(L, 1), luaL_checkinteger(L, 2)); 118 | } 119 | 120 | 121 | static int b_rshift (lua_State *L) { 122 | return b_shift(L, checkunsigned(L, 1), -luaL_checkinteger(L, 2)); 123 | } 124 | 125 | 126 | static int b_arshift (lua_State *L) { 127 | lua_Unsigned r = checkunsigned(L, 1); 128 | lua_Integer i = luaL_checkinteger(L, 2); 129 | if (i < 0 || !(r & ((lua_Unsigned)1 << (LUA_NBITS - 1)))) 130 | return b_shift(L, r, -i); 131 | else { /* arithmetic shift for 'negative' number */ 132 | if (i >= LUA_NBITS) r = ALLONES; 133 | else 134 | r = trim((r >> i) | ~(trim(~(lua_Unsigned)0) >> i)); /* add signal bit */ 135 | pushunsigned(L, r); 136 | return 1; 137 | } 138 | } 139 | 140 | 141 | static int b_rot (lua_State *L, lua_Integer d) { 142 | lua_Unsigned r = checkunsigned(L, 1); 143 | int i = d & (LUA_NBITS - 1); /* i = d % NBITS */ 144 | r = trim(r); 145 | if (i != 0) /* avoid undefined shift of LUA_NBITS when i == 0 */ 146 | r = (r << i) | (r >> (LUA_NBITS - i)); 147 | pushunsigned(L, trim(r)); 148 | return 1; 149 | } 150 | 151 | 152 | static int b_lrot (lua_State *L) { 153 | return b_rot(L, luaL_checkinteger(L, 2)); 154 | } 155 | 156 | 157 | static int b_rrot (lua_State *L) { 158 | return b_rot(L, -luaL_checkinteger(L, 2)); 159 | } 160 | 161 | 162 | /* 163 | ** get field and width arguments for field-manipulation functions, 164 | ** checking whether they are valid. 165 | ** ('luaL_error' called without 'return' to avoid later warnings about 166 | ** 'width' being used uninitialized.) 167 | */ 168 | static int fieldargs (lua_State *L, int farg, int *width) { 169 | lua_Integer f = luaL_checkinteger(L, farg); 170 | lua_Integer w = luaL_optinteger(L, farg + 1, 1); 171 | luaL_argcheck(L, 0 <= f, farg, "field cannot be negative"); 172 | luaL_argcheck(L, 0 < w, farg + 1, "width must be positive"); 173 | if (f + w > LUA_NBITS) 174 | luaL_error(L, "trying to access non-existent bits"); 175 | *width = (int)w; 176 | return (int)f; 177 | } 178 | 179 | 180 | static int b_extract (lua_State *L) { 181 | int w; 182 | lua_Unsigned r = trim(checkunsigned(L, 1)); 183 | int f = fieldargs(L, 2, &w); 184 | r = (r >> f) & mask(w); 185 | pushunsigned(L, r); 186 | return 1; 187 | } 188 | 189 | 190 | static int b_replace (lua_State *L) { 191 | int w; 192 | lua_Unsigned r = trim(checkunsigned(L, 1)); 193 | lua_Unsigned v = trim(checkunsigned(L, 2)); 194 | int f = fieldargs(L, 3, &w); 195 | lua_Unsigned m = mask(w); 196 | r = (r & ~(m << f)) | ((v & m) << f); 197 | pushunsigned(L, r); 198 | return 1; 199 | } 200 | 201 | 202 | static const luaL_Reg bitlib[] = { 203 | {"arshift", b_arshift}, 204 | {"band", b_and}, 205 | {"bnot", b_not}, 206 | {"bor", b_or}, 207 | {"bxor", b_xor}, 208 | {"btest", b_test}, 209 | {"extract", b_extract}, 210 | {"lrotate", b_lrot}, 211 | {"lshift", b_lshift}, 212 | {"replace", b_replace}, 213 | {"rrotate", b_rrot}, 214 | {"rshift", b_rshift}, 215 | {NULL, NULL} 216 | }; 217 | 218 | 219 | 220 | LUAMOD_API int luaopen_bit32 (lua_State *L) { 221 | luaL_newlib(L, bitlib); 222 | return 1; 223 | } 224 | 225 | 226 | #else /* }{ */ 227 | 228 | 229 | LUAMOD_API int luaopen_bit32 (lua_State *L) { 230 | return luaL_error(L, "library 'bit32' has been deprecated"); 231 | } 232 | 233 | #endif /* } */ 234 | -------------------------------------------------------------------------------- /src/lua-5.3.5/src/lcode.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lcode.h,v 1.64.1.1 2017/04/19 17:20:42 roberto Exp $ 3 | ** Code generator for Lua 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef lcode_h 8 | #define lcode_h 9 | 10 | #include "llex.h" 11 | #include "lobject.h" 12 | #include "lopcodes.h" 13 | #include "lparser.h" 14 | 15 | 16 | /* 17 | ** Marks the end of a patch list. It is an invalid value both as an absolute 18 | ** address, and as a list link (would link an element to itself). 19 | */ 20 | #define NO_JUMP (-1) 21 | 22 | 23 | /* 24 | ** grep "ORDER OPR" if you change these enums (ORDER OP) 25 | */ 26 | typedef enum BinOpr { 27 | OPR_ADD, OPR_SUB, OPR_MUL, OPR_MOD, OPR_POW, 28 | OPR_DIV, 29 | OPR_IDIV, 30 | OPR_BAND, OPR_BOR, OPR_BXOR, 31 | OPR_SHL, OPR_SHR, 32 | OPR_CONCAT, 33 | OPR_EQ, OPR_LT, OPR_LE, 34 | OPR_NE, OPR_GT, OPR_GE, 35 | OPR_AND, OPR_OR, 36 | OPR_NOBINOPR 37 | } BinOpr; 38 | 39 | 40 | typedef enum UnOpr { OPR_MINUS, OPR_BNOT, OPR_NOT, OPR_LEN, OPR_NOUNOPR } UnOpr; 41 | 42 | 43 | /* get (pointer to) instruction of given 'expdesc' */ 44 | #define getinstruction(fs,e) ((fs)->f->code[(e)->u.info]) 45 | 46 | #define luaK_codeAsBx(fs,o,A,sBx) luaK_codeABx(fs,o,A,(sBx)+MAXARG_sBx) 47 | 48 | #define luaK_setmultret(fs,e) luaK_setreturns(fs, e, LUA_MULTRET) 49 | 50 | #define luaK_jumpto(fs,t) luaK_patchlist(fs, luaK_jump(fs), t) 51 | 52 | LUAI_FUNC int luaK_codeABx (FuncState *fs, OpCode o, int A, unsigned int Bx); 53 | LUAI_FUNC int luaK_codeABC (FuncState *fs, OpCode o, int A, int B, int C); 54 | LUAI_FUNC int luaK_codek (FuncState *fs, int reg, int k); 55 | LUAI_FUNC void luaK_fixline (FuncState *fs, int line); 56 | LUAI_FUNC void luaK_nil (FuncState *fs, int from, int n); 57 | LUAI_FUNC void luaK_reserveregs (FuncState *fs, int n); 58 | LUAI_FUNC void luaK_checkstack (FuncState *fs, int n); 59 | LUAI_FUNC int luaK_stringK (FuncState *fs, TString *s); 60 | LUAI_FUNC int luaK_intK (FuncState *fs, lua_Integer n); 61 | LUAI_FUNC void luaK_dischargevars (FuncState *fs, expdesc *e); 62 | LUAI_FUNC int luaK_exp2anyreg (FuncState *fs, expdesc *e); 63 | LUAI_FUNC void luaK_exp2anyregup (FuncState *fs, expdesc *e); 64 | LUAI_FUNC void luaK_exp2nextreg (FuncState *fs, expdesc *e); 65 | LUAI_FUNC void luaK_exp2val (FuncState *fs, expdesc *e); 66 | LUAI_FUNC int luaK_exp2RK (FuncState *fs, expdesc *e); 67 | LUAI_FUNC void luaK_self (FuncState *fs, expdesc *e, expdesc *key); 68 | LUAI_FUNC void luaK_indexed (FuncState *fs, expdesc *t, expdesc *k); 69 | LUAI_FUNC void luaK_goiftrue (FuncState *fs, expdesc *e); 70 | LUAI_FUNC void luaK_goiffalse (FuncState *fs, expdesc *e); 71 | LUAI_FUNC void luaK_storevar (FuncState *fs, expdesc *var, expdesc *e); 72 | LUAI_FUNC void luaK_setreturns (FuncState *fs, expdesc *e, int nresults); 73 | LUAI_FUNC void luaK_setoneret (FuncState *fs, expdesc *e); 74 | LUAI_FUNC int luaK_jump (FuncState *fs); 75 | LUAI_FUNC void luaK_ret (FuncState *fs, int first, int nret); 76 | LUAI_FUNC void luaK_patchlist (FuncState *fs, int list, int target); 77 | LUAI_FUNC void luaK_patchtohere (FuncState *fs, int list); 78 | LUAI_FUNC void luaK_patchclose (FuncState *fs, int list, int level); 79 | LUAI_FUNC void luaK_concat (FuncState *fs, int *l1, int l2); 80 | LUAI_FUNC int luaK_getlabel (FuncState *fs); 81 | LUAI_FUNC void luaK_prefix (FuncState *fs, UnOpr op, expdesc *v, int line); 82 | LUAI_FUNC void luaK_infix (FuncState *fs, BinOpr op, expdesc *v); 83 | LUAI_FUNC void luaK_posfix (FuncState *fs, BinOpr op, expdesc *v1, 84 | expdesc *v2, int line); 85 | LUAI_FUNC void luaK_setlist (FuncState *fs, int base, int nelems, int tostore); 86 | 87 | 88 | #endif 89 | -------------------------------------------------------------------------------- /src/lua-5.3.5/src/lcorolib.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lcorolib.c,v 1.10.1.1 2017/04/19 17:20:42 roberto Exp $ 3 | ** Coroutine Library 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #define lcorolib_c 8 | #define LUA_LIB 9 | 10 | #include "lprefix.h" 11 | 12 | 13 | #include 14 | 15 | #include "lua.h" 16 | 17 | #include "lauxlib.h" 18 | #include "lualib.h" 19 | 20 | 21 | static lua_State *getco (lua_State *L) { 22 | lua_State *co = lua_tothread(L, 1); 23 | luaL_argcheck(L, co, 1, "thread expected"); 24 | return co; 25 | } 26 | 27 | 28 | static int auxresume (lua_State *L, lua_State *co, int narg) { 29 | int status; 30 | if (!lua_checkstack(co, narg)) { 31 | lua_pushliteral(L, "too many arguments to resume"); 32 | return -1; /* error flag */ 33 | } 34 | if (lua_status(co) == LUA_OK && lua_gettop(co) == 0) { 35 | lua_pushliteral(L, "cannot resume dead coroutine"); 36 | return -1; /* error flag */ 37 | } 38 | lua_xmove(L, co, narg); 39 | status = lua_resume(co, L, narg); 40 | if (status == LUA_OK || status == LUA_YIELD) { 41 | int nres = lua_gettop(co); 42 | if (!lua_checkstack(L, nres + 1)) { 43 | lua_pop(co, nres); /* remove results anyway */ 44 | lua_pushliteral(L, "too many results to resume"); 45 | return -1; /* error flag */ 46 | } 47 | lua_xmove(co, L, nres); /* move yielded values */ 48 | return nres; 49 | } 50 | else { 51 | lua_xmove(co, L, 1); /* move error message */ 52 | return -1; /* error flag */ 53 | } 54 | } 55 | 56 | 57 | static int luaB_coresume (lua_State *L) { 58 | lua_State *co = getco(L); 59 | int r; 60 | r = auxresume(L, co, lua_gettop(L) - 1); 61 | if (r < 0) { 62 | lua_pushboolean(L, 0); 63 | lua_insert(L, -2); 64 | return 2; /* return false + error message */ 65 | } 66 | else { 67 | lua_pushboolean(L, 1); 68 | lua_insert(L, -(r + 1)); 69 | return r + 1; /* return true + 'resume' returns */ 70 | } 71 | } 72 | 73 | 74 | static int luaB_auxwrap (lua_State *L) { 75 | lua_State *co = lua_tothread(L, lua_upvalueindex(1)); 76 | int r = auxresume(L, co, lua_gettop(L)); 77 | if (r < 0) { 78 | if (lua_type(L, -1) == LUA_TSTRING) { /* error object is a string? */ 79 | luaL_where(L, 1); /* add extra info */ 80 | lua_insert(L, -2); 81 | lua_concat(L, 2); 82 | } 83 | return lua_error(L); /* propagate error */ 84 | } 85 | return r; 86 | } 87 | 88 | 89 | static int luaB_cocreate (lua_State *L) { 90 | lua_State *NL; 91 | luaL_checktype(L, 1, LUA_TFUNCTION); 92 | NL = lua_newthread(L); 93 | lua_pushvalue(L, 1); /* move function to top */ 94 | lua_xmove(L, NL, 1); /* move function from L to NL */ 95 | return 1; 96 | } 97 | 98 | 99 | static int luaB_cowrap (lua_State *L) { 100 | luaB_cocreate(L); 101 | lua_pushcclosure(L, luaB_auxwrap, 1); 102 | return 1; 103 | } 104 | 105 | 106 | static int luaB_yield (lua_State *L) { 107 | return lua_yield(L, lua_gettop(L)); 108 | } 109 | 110 | 111 | static int luaB_costatus (lua_State *L) { 112 | lua_State *co = getco(L); 113 | if (L == co) lua_pushliteral(L, "running"); 114 | else { 115 | switch (lua_status(co)) { 116 | case LUA_YIELD: 117 | lua_pushliteral(L, "suspended"); 118 | break; 119 | case LUA_OK: { 120 | lua_Debug ar; 121 | if (lua_getstack(co, 0, &ar) > 0) /* does it have frames? */ 122 | lua_pushliteral(L, "normal"); /* it is running */ 123 | else if (lua_gettop(co) == 0) 124 | lua_pushliteral(L, "dead"); 125 | else 126 | lua_pushliteral(L, "suspended"); /* initial state */ 127 | break; 128 | } 129 | default: /* some error occurred */ 130 | lua_pushliteral(L, "dead"); 131 | break; 132 | } 133 | } 134 | return 1; 135 | } 136 | 137 | 138 | static int luaB_yieldable (lua_State *L) { 139 | lua_pushboolean(L, lua_isyieldable(L)); 140 | return 1; 141 | } 142 | 143 | 144 | static int luaB_corunning (lua_State *L) { 145 | int ismain = lua_pushthread(L); 146 | lua_pushboolean(L, ismain); 147 | return 2; 148 | } 149 | 150 | 151 | static const luaL_Reg co_funcs[] = { 152 | {"create", luaB_cocreate}, 153 | {"resume", luaB_coresume}, 154 | {"running", luaB_corunning}, 155 | {"status", luaB_costatus}, 156 | {"wrap", luaB_cowrap}, 157 | {"yield", luaB_yield}, 158 | {"isyieldable", luaB_yieldable}, 159 | {NULL, NULL} 160 | }; 161 | 162 | 163 | 164 | LUAMOD_API int luaopen_coroutine (lua_State *L) { 165 | luaL_newlib(L, co_funcs); 166 | return 1; 167 | } 168 | 169 | -------------------------------------------------------------------------------- /src/lua-5.3.5/src/lctype.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lctype.c,v 1.12.1.1 2017/04/19 17:20:42 roberto Exp $ 3 | ** 'ctype' functions for Lua 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #define lctype_c 8 | #define LUA_CORE 9 | 10 | #include "lprefix.h" 11 | 12 | 13 | #include "lctype.h" 14 | 15 | #if !LUA_USE_CTYPE /* { */ 16 | 17 | #include 18 | 19 | LUAI_DDEF const lu_byte luai_ctype_[UCHAR_MAX + 2] = { 20 | 0x00, /* EOZ */ 21 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0. */ 22 | 0x00, 0x08, 0x08, 0x08, 0x08, 0x08, 0x00, 0x00, 23 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 1. */ 24 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 25 | 0x0c, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, /* 2. */ 26 | 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 27 | 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, /* 3. */ 28 | 0x16, 0x16, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 29 | 0x04, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x05, /* 4. */ 30 | 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 31 | 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, /* 5. */ 32 | 0x05, 0x05, 0x05, 0x04, 0x04, 0x04, 0x04, 0x05, 33 | 0x04, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x05, /* 6. */ 34 | 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 35 | 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, /* 7. */ 36 | 0x05, 0x05, 0x05, 0x04, 0x04, 0x04, 0x04, 0x00, 37 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 8. */ 38 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 39 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 9. */ 40 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 41 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* a. */ 42 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 43 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* b. */ 44 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 45 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* c. */ 46 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 47 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* d. */ 48 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 49 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* e. */ 50 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 51 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* f. */ 52 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 53 | }; 54 | 55 | #endif /* } */ 56 | -------------------------------------------------------------------------------- /src/lua-5.3.5/src/lctype.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lctype.h,v 1.12.1.1 2013/04/12 18:48:47 roberto Exp $ 3 | ** 'ctype' functions for Lua 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef lctype_h 8 | #define lctype_h 9 | 10 | #include "lua.h" 11 | 12 | 13 | /* 14 | ** WARNING: the functions defined here do not necessarily correspond 15 | ** to the similar functions in the standard C ctype.h. They are 16 | ** optimized for the specific needs of Lua 17 | */ 18 | 19 | #if !defined(LUA_USE_CTYPE) 20 | 21 | #if 'A' == 65 && '0' == 48 22 | /* ASCII case: can use its own tables; faster and fixed */ 23 | #define LUA_USE_CTYPE 0 24 | #else 25 | /* must use standard C ctype */ 26 | #define LUA_USE_CTYPE 1 27 | #endif 28 | 29 | #endif 30 | 31 | 32 | #if !LUA_USE_CTYPE /* { */ 33 | 34 | #include 35 | 36 | #include "llimits.h" 37 | 38 | 39 | #define ALPHABIT 0 40 | #define DIGITBIT 1 41 | #define PRINTBIT 2 42 | #define SPACEBIT 3 43 | #define XDIGITBIT 4 44 | 45 | 46 | #define MASK(B) (1 << (B)) 47 | 48 | 49 | /* 50 | ** add 1 to char to allow index -1 (EOZ) 51 | */ 52 | #define testprop(c,p) (luai_ctype_[(c)+1] & (p)) 53 | 54 | /* 55 | ** 'lalpha' (Lua alphabetic) and 'lalnum' (Lua alphanumeric) both include '_' 56 | */ 57 | #define lislalpha(c) testprop(c, MASK(ALPHABIT)) 58 | #define lislalnum(c) testprop(c, (MASK(ALPHABIT) | MASK(DIGITBIT))) 59 | #define lisdigit(c) testprop(c, MASK(DIGITBIT)) 60 | #define lisspace(c) testprop(c, MASK(SPACEBIT)) 61 | #define lisprint(c) testprop(c, MASK(PRINTBIT)) 62 | #define lisxdigit(c) testprop(c, MASK(XDIGITBIT)) 63 | 64 | /* 65 | ** this 'ltolower' only works for alphabetic characters 66 | */ 67 | #define ltolower(c) ((c) | ('A' ^ 'a')) 68 | 69 | 70 | /* two more entries for 0 and -1 (EOZ) */ 71 | LUAI_DDEC const lu_byte luai_ctype_[UCHAR_MAX + 2]; 72 | 73 | 74 | #else /* }{ */ 75 | 76 | /* 77 | ** use standard C ctypes 78 | */ 79 | 80 | #include 81 | 82 | 83 | #define lislalpha(c) (isalpha(c) || (c) == '_') 84 | #define lislalnum(c) (isalnum(c) || (c) == '_') 85 | #define lisdigit(c) (isdigit(c)) 86 | #define lisspace(c) (isspace(c)) 87 | #define lisprint(c) (isprint(c)) 88 | #define lisxdigit(c) (isxdigit(c)) 89 | 90 | #define ltolower(c) (tolower(c)) 91 | 92 | #endif /* } */ 93 | 94 | #endif 95 | 96 | -------------------------------------------------------------------------------- /src/lua-5.3.5/src/ldebug.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: ldebug.h,v 2.14.1.1 2017/04/19 17:20:42 roberto Exp $ 3 | ** Auxiliary functions from Debug Interface module 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef ldebug_h 8 | #define ldebug_h 9 | 10 | 11 | #include "lstate.h" 12 | 13 | 14 | #define pcRel(pc, p) (cast(int, (pc) - (p)->code) - 1) 15 | 16 | #define getfuncline(f,pc) (((f)->lineinfo) ? (f)->lineinfo[pc] : -1) 17 | 18 | #define resethookcount(L) (L->hookcount = L->basehookcount) 19 | 20 | 21 | LUAI_FUNC l_noret luaG_typeerror (lua_State *L, const TValue *o, 22 | const char *opname); 23 | LUAI_FUNC l_noret luaG_concaterror (lua_State *L, const TValue *p1, 24 | const TValue *p2); 25 | LUAI_FUNC l_noret luaG_opinterror (lua_State *L, const TValue *p1, 26 | const TValue *p2, 27 | const char *msg); 28 | LUAI_FUNC l_noret luaG_tointerror (lua_State *L, const TValue *p1, 29 | const TValue *p2); 30 | LUAI_FUNC l_noret luaG_ordererror (lua_State *L, const TValue *p1, 31 | const TValue *p2); 32 | LUAI_FUNC l_noret luaG_runerror (lua_State *L, const char *fmt, ...); 33 | LUAI_FUNC const char *luaG_addinfo (lua_State *L, const char *msg, 34 | TString *src, int line); 35 | LUAI_FUNC l_noret luaG_errormsg (lua_State *L); 36 | LUAI_FUNC void luaG_traceexec (lua_State *L); 37 | 38 | 39 | #endif 40 | -------------------------------------------------------------------------------- /src/lua-5.3.5/src/ldo.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: ldo.h,v 2.29.1.1 2017/04/19 17:20:42 roberto Exp $ 3 | ** Stack and Call structure of Lua 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef ldo_h 8 | #define ldo_h 9 | 10 | 11 | #include "lobject.h" 12 | #include "lstate.h" 13 | #include "lzio.h" 14 | 15 | 16 | /* 17 | ** Macro to check stack size and grow stack if needed. Parameters 18 | ** 'pre'/'pos' allow the macro to preserve a pointer into the 19 | ** stack across reallocations, doing the work only when needed. 20 | ** 'condmovestack' is used in heavy tests to force a stack reallocation 21 | ** at every check. 22 | */ 23 | #define luaD_checkstackaux(L,n,pre,pos) \ 24 | if (L->stack_last - L->top <= (n)) \ 25 | { pre; luaD_growstack(L, n); pos; } else { condmovestack(L,pre,pos); } 26 | 27 | /* In general, 'pre'/'pos' are empty (nothing to save) */ 28 | #define luaD_checkstack(L,n) luaD_checkstackaux(L,n,(void)0,(void)0) 29 | 30 | 31 | 32 | #define savestack(L,p) ((char *)(p) - (char *)L->stack) 33 | #define restorestack(L,n) ((TValue *)((char *)L->stack + (n))) 34 | 35 | 36 | /* type of protected functions, to be ran by 'runprotected' */ 37 | typedef void (*Pfunc) (lua_State *L, void *ud); 38 | 39 | LUAI_FUNC int luaD_protectedparser (lua_State *L, ZIO *z, const char *name, 40 | const char *mode); 41 | LUAI_FUNC void luaD_hook (lua_State *L, int event, int line); 42 | LUAI_FUNC int luaD_precall (lua_State *L, StkId func, int nresults); 43 | LUAI_FUNC void luaD_call (lua_State *L, StkId func, int nResults); 44 | LUAI_FUNC void luaD_callnoyield (lua_State *L, StkId func, int nResults); 45 | LUAI_FUNC int luaD_pcall (lua_State *L, Pfunc func, void *u, 46 | ptrdiff_t oldtop, ptrdiff_t ef); 47 | LUAI_FUNC int luaD_poscall (lua_State *L, CallInfo *ci, StkId firstResult, 48 | int nres); 49 | LUAI_FUNC void luaD_reallocstack (lua_State *L, int newsize); 50 | LUAI_FUNC void luaD_growstack (lua_State *L, int n); 51 | LUAI_FUNC void luaD_shrinkstack (lua_State *L); 52 | LUAI_FUNC void luaD_inctop (lua_State *L); 53 | 54 | LUAI_FUNC l_noret luaD_throw (lua_State *L, int errcode); 55 | LUAI_FUNC int luaD_rawrunprotected (lua_State *L, Pfunc f, void *ud); 56 | 57 | #endif 58 | 59 | -------------------------------------------------------------------------------- /src/lua-5.3.5/src/ldump.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: ldump.c,v 2.37.1.1 2017/04/19 17:20:42 roberto Exp $ 3 | ** save precompiled Lua chunks 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #define ldump_c 8 | #define LUA_CORE 9 | 10 | #include "lprefix.h" 11 | 12 | 13 | #include 14 | 15 | #include "lua.h" 16 | 17 | #include "lobject.h" 18 | #include "lstate.h" 19 | #include "lundump.h" 20 | 21 | 22 | typedef struct { 23 | lua_State *L; 24 | lua_Writer writer; 25 | void *data; 26 | int strip; 27 | int status; 28 | } DumpState; 29 | 30 | 31 | /* 32 | ** All high-level dumps go through DumpVector; you can change it to 33 | ** change the endianness of the result 34 | */ 35 | #define DumpVector(v,n,D) DumpBlock(v,(n)*sizeof((v)[0]),D) 36 | 37 | #define DumpLiteral(s,D) DumpBlock(s, sizeof(s) - sizeof(char), D) 38 | 39 | 40 | static void DumpBlock (const void *b, size_t size, DumpState *D) { 41 | if (D->status == 0 && size > 0) { 42 | lua_unlock(D->L); 43 | D->status = (*D->writer)(D->L, b, size, D->data); 44 | lua_lock(D->L); 45 | } 46 | } 47 | 48 | 49 | #define DumpVar(x,D) DumpVector(&x,1,D) 50 | 51 | 52 | static void DumpByte (int y, DumpState *D) { 53 | lu_byte x = (lu_byte)y; 54 | DumpVar(x, D); 55 | } 56 | 57 | 58 | static void DumpInt (int x, DumpState *D) { 59 | DumpVar(x, D); 60 | } 61 | 62 | 63 | static void DumpNumber (lua_Number x, DumpState *D) { 64 | DumpVar(x, D); 65 | } 66 | 67 | 68 | static void DumpInteger (lua_Integer x, DumpState *D) { 69 | DumpVar(x, D); 70 | } 71 | 72 | 73 | static void DumpString (const TString *s, DumpState *D) { 74 | if (s == NULL) 75 | DumpByte(0, D); 76 | else { 77 | size_t size = tsslen(s) + 1; /* include trailing '\0' */ 78 | const char *str = getstr(s); 79 | if (size < 0xFF) 80 | DumpByte(cast_int(size), D); 81 | else { 82 | DumpByte(0xFF, D); 83 | DumpVar(size, D); 84 | } 85 | DumpVector(str, size - 1, D); /* no need to save '\0' */ 86 | } 87 | } 88 | 89 | 90 | static void DumpCode (const Proto *f, DumpState *D) { 91 | DumpInt(f->sizecode, D); 92 | DumpVector(f->code, f->sizecode, D); 93 | } 94 | 95 | 96 | static void DumpFunction(const Proto *f, TString *psource, DumpState *D); 97 | 98 | static void DumpConstants (const Proto *f, DumpState *D) { 99 | int i; 100 | int n = f->sizek; 101 | DumpInt(n, D); 102 | for (i = 0; i < n; i++) { 103 | const TValue *o = &f->k[i]; 104 | DumpByte(ttype(o), D); 105 | switch (ttype(o)) { 106 | case LUA_TNIL: 107 | break; 108 | case LUA_TBOOLEAN: 109 | DumpByte(bvalue(o), D); 110 | break; 111 | case LUA_TNUMFLT: 112 | DumpNumber(fltvalue(o), D); 113 | break; 114 | case LUA_TNUMINT: 115 | DumpInteger(ivalue(o), D); 116 | break; 117 | case LUA_TSHRSTR: 118 | case LUA_TLNGSTR: 119 | DumpString(tsvalue(o), D); 120 | break; 121 | default: 122 | lua_assert(0); 123 | } 124 | } 125 | } 126 | 127 | 128 | static void DumpProtos (const Proto *f, DumpState *D) { 129 | int i; 130 | int n = f->sizep; 131 | DumpInt(n, D); 132 | for (i = 0; i < n; i++) 133 | DumpFunction(f->p[i], f->source, D); 134 | } 135 | 136 | 137 | static void DumpUpvalues (const Proto *f, DumpState *D) { 138 | int i, n = f->sizeupvalues; 139 | DumpInt(n, D); 140 | for (i = 0; i < n; i++) { 141 | DumpByte(f->upvalues[i].instack, D); 142 | DumpByte(f->upvalues[i].idx, D); 143 | } 144 | } 145 | 146 | 147 | static void DumpDebug (const Proto *f, DumpState *D) { 148 | int i, n; 149 | n = (D->strip) ? 0 : f->sizelineinfo; 150 | DumpInt(n, D); 151 | DumpVector(f->lineinfo, n, D); 152 | n = (D->strip) ? 0 : f->sizelocvars; 153 | DumpInt(n, D); 154 | for (i = 0; i < n; i++) { 155 | DumpString(f->locvars[i].varname, D); 156 | DumpInt(f->locvars[i].startpc, D); 157 | DumpInt(f->locvars[i].endpc, D); 158 | } 159 | n = (D->strip) ? 0 : f->sizeupvalues; 160 | DumpInt(n, D); 161 | for (i = 0; i < n; i++) 162 | DumpString(f->upvalues[i].name, D); 163 | } 164 | 165 | 166 | static void DumpFunction (const Proto *f, TString *psource, DumpState *D) { 167 | if (D->strip || f->source == psource) 168 | DumpString(NULL, D); /* no debug info or same source as its parent */ 169 | else 170 | DumpString(f->source, D); 171 | DumpInt(f->linedefined, D); 172 | DumpInt(f->lastlinedefined, D); 173 | DumpByte(f->numparams, D); 174 | DumpByte(f->is_vararg, D); 175 | DumpByte(f->maxstacksize, D); 176 | DumpCode(f, D); 177 | DumpConstants(f, D); 178 | DumpUpvalues(f, D); 179 | DumpProtos(f, D); 180 | DumpDebug(f, D); 181 | } 182 | 183 | 184 | static void DumpHeader (DumpState *D) { 185 | DumpLiteral(LUA_SIGNATURE, D); 186 | DumpByte(LUAC_VERSION, D); 187 | DumpByte(LUAC_FORMAT, D); 188 | DumpLiteral(LUAC_DATA, D); 189 | DumpByte(sizeof(int), D); 190 | DumpByte(sizeof(size_t), D); 191 | DumpByte(sizeof(Instruction), D); 192 | DumpByte(sizeof(lua_Integer), D); 193 | DumpByte(sizeof(lua_Number), D); 194 | DumpInteger(LUAC_INT, D); 195 | DumpNumber(LUAC_NUM, D); 196 | } 197 | 198 | 199 | /* 200 | ** dump Lua function as precompiled chunk 201 | */ 202 | int luaU_dump(lua_State *L, const Proto *f, lua_Writer w, void *data, 203 | int strip) { 204 | DumpState D; 205 | D.L = L; 206 | D.writer = w; 207 | D.data = data; 208 | D.strip = strip; 209 | D.status = 0; 210 | DumpHeader(&D); 211 | DumpByte(f->sizeupvalues, &D); 212 | DumpFunction(f, NULL, &D); 213 | return D.status; 214 | } 215 | 216 | -------------------------------------------------------------------------------- /src/lua-5.3.5/src/lfunc.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lfunc.c,v 2.45.1.1 2017/04/19 17:39:34 roberto Exp $ 3 | ** Auxiliary functions to manipulate prototypes and closures 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #define lfunc_c 8 | #define LUA_CORE 9 | 10 | #include "lprefix.h" 11 | 12 | 13 | #include 14 | 15 | #include "lua.h" 16 | 17 | #include "lfunc.h" 18 | #include "lgc.h" 19 | #include "lmem.h" 20 | #include "lobject.h" 21 | #include "lstate.h" 22 | 23 | 24 | 25 | CClosure *luaF_newCclosure (lua_State *L, int n) { 26 | GCObject *o = luaC_newobj(L, LUA_TCCL, sizeCclosure(n)); 27 | CClosure *c = gco2ccl(o); 28 | c->nupvalues = cast_byte(n); 29 | return c; 30 | } 31 | 32 | 33 | LClosure *luaF_newLclosure (lua_State *L, int n) { 34 | GCObject *o = luaC_newobj(L, LUA_TLCL, sizeLclosure(n)); 35 | LClosure *c = gco2lcl(o); 36 | c->p = NULL; 37 | c->nupvalues = cast_byte(n); 38 | while (n--) c->upvals[n] = NULL; 39 | return c; 40 | } 41 | 42 | /* 43 | ** fill a closure with new closed upvalues 44 | */ 45 | void luaF_initupvals (lua_State *L, LClosure *cl) { 46 | int i; 47 | for (i = 0; i < cl->nupvalues; i++) { 48 | UpVal *uv = luaM_new(L, UpVal); 49 | uv->refcount = 1; 50 | uv->v = &uv->u.value; /* make it closed */ 51 | setnilvalue(uv->v); 52 | cl->upvals[i] = uv; 53 | } 54 | } 55 | 56 | 57 | UpVal *luaF_findupval (lua_State *L, StkId level) { 58 | UpVal **pp = &L->openupval; 59 | UpVal *p; 60 | UpVal *uv; 61 | lua_assert(isintwups(L) || L->openupval == NULL); 62 | while (*pp != NULL && (p = *pp)->v >= level) { 63 | lua_assert(upisopen(p)); 64 | if (p->v == level) /* found a corresponding upvalue? */ 65 | return p; /* return it */ 66 | pp = &p->u.open.next; 67 | } 68 | /* not found: create a new upvalue */ 69 | uv = luaM_new(L, UpVal); 70 | uv->refcount = 0; 71 | uv->u.open.next = *pp; /* link it to list of open upvalues */ 72 | uv->u.open.touched = 1; 73 | *pp = uv; 74 | uv->v = level; /* current value lives in the stack */ 75 | if (!isintwups(L)) { /* thread not in list of threads with upvalues? */ 76 | L->twups = G(L)->twups; /* link it to the list */ 77 | G(L)->twups = L; 78 | } 79 | return uv; 80 | } 81 | 82 | 83 | void luaF_close (lua_State *L, StkId level) { 84 | UpVal *uv; 85 | while (L->openupval != NULL && (uv = L->openupval)->v >= level) { 86 | lua_assert(upisopen(uv)); 87 | L->openupval = uv->u.open.next; /* remove from 'open' list */ 88 | if (uv->refcount == 0) /* no references? */ 89 | luaM_free(L, uv); /* free upvalue */ 90 | else { 91 | setobj(L, &uv->u.value, uv->v); /* move value to upvalue slot */ 92 | uv->v = &uv->u.value; /* now current value lives here */ 93 | luaC_upvalbarrier(L, uv); 94 | } 95 | } 96 | } 97 | 98 | 99 | Proto *luaF_newproto (lua_State *L) { 100 | GCObject *o = luaC_newobj(L, LUA_TPROTO, sizeof(Proto)); 101 | Proto *f = gco2p(o); 102 | f->k = NULL; 103 | f->sizek = 0; 104 | f->p = NULL; 105 | f->sizep = 0; 106 | f->code = NULL; 107 | f->cache = NULL; 108 | f->sizecode = 0; 109 | f->lineinfo = NULL; 110 | f->sizelineinfo = 0; 111 | f->upvalues = NULL; 112 | f->sizeupvalues = 0; 113 | f->numparams = 0; 114 | f->is_vararg = 0; 115 | f->maxstacksize = 0; 116 | f->locvars = NULL; 117 | f->sizelocvars = 0; 118 | f->linedefined = 0; 119 | f->lastlinedefined = 0; 120 | f->source = NULL; 121 | return f; 122 | } 123 | 124 | 125 | void luaF_freeproto (lua_State *L, Proto *f) { 126 | luaM_freearray(L, f->code, f->sizecode); 127 | luaM_freearray(L, f->p, f->sizep); 128 | luaM_freearray(L, f->k, f->sizek); 129 | luaM_freearray(L, f->lineinfo, f->sizelineinfo); 130 | luaM_freearray(L, f->locvars, f->sizelocvars); 131 | luaM_freearray(L, f->upvalues, f->sizeupvalues); 132 | luaM_free(L, f); 133 | } 134 | 135 | 136 | /* 137 | ** Look for n-th local variable at line 'line' in function 'func'. 138 | ** Returns NULL if not found. 139 | */ 140 | const char *luaF_getlocalname (const Proto *f, int local_number, int pc) { 141 | int i; 142 | for (i = 0; isizelocvars && f->locvars[i].startpc <= pc; i++) { 143 | if (pc < f->locvars[i].endpc) { /* is variable active? */ 144 | local_number--; 145 | if (local_number == 0) 146 | return getstr(f->locvars[i].varname); 147 | } 148 | } 149 | return NULL; /* not found */ 150 | } 151 | 152 | -------------------------------------------------------------------------------- /src/lua-5.3.5/src/lfunc.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lfunc.h,v 2.15.1.1 2017/04/19 17:39:34 roberto Exp $ 3 | ** Auxiliary functions to manipulate prototypes and closures 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef lfunc_h 8 | #define lfunc_h 9 | 10 | 11 | #include "lobject.h" 12 | 13 | 14 | #define sizeCclosure(n) (cast(int, sizeof(CClosure)) + \ 15 | cast(int, sizeof(TValue)*((n)-1))) 16 | 17 | #define sizeLclosure(n) (cast(int, sizeof(LClosure)) + \ 18 | cast(int, sizeof(TValue *)*((n)-1))) 19 | 20 | 21 | /* test whether thread is in 'twups' list */ 22 | #define isintwups(L) (L->twups != L) 23 | 24 | 25 | /* 26 | ** maximum number of upvalues in a closure (both C and Lua). (Value 27 | ** must fit in a VM register.) 28 | */ 29 | #define MAXUPVAL 255 30 | 31 | 32 | /* 33 | ** Upvalues for Lua closures 34 | */ 35 | struct UpVal { 36 | TValue *v; /* points to stack or to its own value */ 37 | lu_mem refcount; /* reference counter */ 38 | union { 39 | struct { /* (when open) */ 40 | UpVal *next; /* linked list */ 41 | int touched; /* mark to avoid cycles with dead threads */ 42 | } open; 43 | TValue value; /* the value (when closed) */ 44 | } u; 45 | }; 46 | 47 | #define upisopen(up) ((up)->v != &(up)->u.value) 48 | 49 | 50 | LUAI_FUNC Proto *luaF_newproto (lua_State *L); 51 | LUAI_FUNC CClosure *luaF_newCclosure (lua_State *L, int nelems); 52 | LUAI_FUNC LClosure *luaF_newLclosure (lua_State *L, int nelems); 53 | LUAI_FUNC void luaF_initupvals (lua_State *L, LClosure *cl); 54 | LUAI_FUNC UpVal *luaF_findupval (lua_State *L, StkId level); 55 | LUAI_FUNC void luaF_close (lua_State *L, StkId level); 56 | LUAI_FUNC void luaF_freeproto (lua_State *L, Proto *f); 57 | LUAI_FUNC const char *luaF_getlocalname (const Proto *func, int local_number, 58 | int pc); 59 | 60 | 61 | #endif 62 | -------------------------------------------------------------------------------- /src/lua-5.3.5/src/lgc.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lgc.h,v 2.91.1.1 2017/04/19 17:39:34 roberto Exp $ 3 | ** Garbage Collector 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef lgc_h 8 | #define lgc_h 9 | 10 | 11 | #include "lobject.h" 12 | #include "lstate.h" 13 | 14 | /* 15 | ** Collectable objects may have one of three colors: white, which 16 | ** means the object is not marked; gray, which means the 17 | ** object is marked, but its references may be not marked; and 18 | ** black, which means that the object and all its references are marked. 19 | ** The main invariant of the garbage collector, while marking objects, 20 | ** is that a black object can never point to a white one. Moreover, 21 | ** any gray object must be in a "gray list" (gray, grayagain, weak, 22 | ** allweak, ephemeron) so that it can be visited again before finishing 23 | ** the collection cycle. These lists have no meaning when the invariant 24 | ** is not being enforced (e.g., sweep phase). 25 | */ 26 | 27 | 28 | 29 | /* how much to allocate before next GC step */ 30 | #if !defined(GCSTEPSIZE) 31 | /* ~100 small strings */ 32 | #define GCSTEPSIZE (cast_int(100 * sizeof(TString))) 33 | #endif 34 | 35 | 36 | /* 37 | ** Possible states of the Garbage Collector 38 | */ 39 | #define GCSpropagate 0 40 | #define GCSatomic 1 41 | #define GCSswpallgc 2 42 | #define GCSswpfinobj 3 43 | #define GCSswptobefnz 4 44 | #define GCSswpend 5 45 | #define GCScallfin 6 46 | #define GCSpause 7 47 | 48 | 49 | #define issweepphase(g) \ 50 | (GCSswpallgc <= (g)->gcstate && (g)->gcstate <= GCSswpend) 51 | 52 | 53 | /* 54 | ** macro to tell when main invariant (white objects cannot point to black 55 | ** ones) must be kept. During a collection, the sweep 56 | ** phase may break the invariant, as objects turned white may point to 57 | ** still-black objects. The invariant is restored when sweep ends and 58 | ** all objects are white again. 59 | */ 60 | 61 | #define keepinvariant(g) ((g)->gcstate <= GCSatomic) 62 | 63 | 64 | /* 65 | ** some useful bit tricks 66 | */ 67 | #define resetbits(x,m) ((x) &= cast(lu_byte, ~(m))) 68 | #define setbits(x,m) ((x) |= (m)) 69 | #define testbits(x,m) ((x) & (m)) 70 | #define bitmask(b) (1<<(b)) 71 | #define bit2mask(b1,b2) (bitmask(b1) | bitmask(b2)) 72 | #define l_setbit(x,b) setbits(x, bitmask(b)) 73 | #define resetbit(x,b) resetbits(x, bitmask(b)) 74 | #define testbit(x,b) testbits(x, bitmask(b)) 75 | 76 | 77 | /* Layout for bit use in 'marked' field: */ 78 | #define WHITE0BIT 0 /* object is white (type 0) */ 79 | #define WHITE1BIT 1 /* object is white (type 1) */ 80 | #define BLACKBIT 2 /* object is black */ 81 | #define FINALIZEDBIT 3 /* object has been marked for finalization */ 82 | /* bit 7 is currently used by tests (luaL_checkmemory) */ 83 | 84 | #define WHITEBITS bit2mask(WHITE0BIT, WHITE1BIT) 85 | 86 | 87 | #define iswhite(x) testbits((x)->marked, WHITEBITS) 88 | #define isblack(x) testbit((x)->marked, BLACKBIT) 89 | #define isgray(x) /* neither white nor black */ \ 90 | (!testbits((x)->marked, WHITEBITS | bitmask(BLACKBIT))) 91 | 92 | #define tofinalize(x) testbit((x)->marked, FINALIZEDBIT) 93 | 94 | #define otherwhite(g) ((g)->currentwhite ^ WHITEBITS) 95 | #define isdeadm(ow,m) (!(((m) ^ WHITEBITS) & (ow))) 96 | #define isdead(g,v) isdeadm(otherwhite(g), (v)->marked) 97 | 98 | #define changewhite(x) ((x)->marked ^= WHITEBITS) 99 | #define gray2black(x) l_setbit((x)->marked, BLACKBIT) 100 | 101 | #define luaC_white(g) cast(lu_byte, (g)->currentwhite & WHITEBITS) 102 | 103 | 104 | /* 105 | ** Does one step of collection when debt becomes positive. 'pre'/'pos' 106 | ** allows some adjustments to be done only when needed. macro 107 | ** 'condchangemem' is used only for heavy tests (forcing a full 108 | ** GC cycle on every opportunity) 109 | */ 110 | #define luaC_condGC(L,pre,pos) \ 111 | { if (G(L)->GCdebt > 0) { pre; luaC_step(L); pos;}; \ 112 | condchangemem(L,pre,pos); } 113 | 114 | /* more often than not, 'pre'/'pos' are empty */ 115 | #define luaC_checkGC(L) luaC_condGC(L,(void)0,(void)0) 116 | 117 | 118 | #define luaC_barrier(L,p,v) ( \ 119 | (iscollectable(v) && isblack(p) && iswhite(gcvalue(v))) ? \ 120 | luaC_barrier_(L,obj2gco(p),gcvalue(v)) : cast_void(0)) 121 | 122 | #define luaC_barrierback(L,p,v) ( \ 123 | (iscollectable(v) && isblack(p) && iswhite(gcvalue(v))) ? \ 124 | luaC_barrierback_(L,p) : cast_void(0)) 125 | 126 | #define luaC_objbarrier(L,p,o) ( \ 127 | (isblack(p) && iswhite(o)) ? \ 128 | luaC_barrier_(L,obj2gco(p),obj2gco(o)) : cast_void(0)) 129 | 130 | #define luaC_upvalbarrier(L,uv) ( \ 131 | (iscollectable((uv)->v) && !upisopen(uv)) ? \ 132 | luaC_upvalbarrier_(L,uv) : cast_void(0)) 133 | 134 | LUAI_FUNC void luaC_fix (lua_State *L, GCObject *o); 135 | LUAI_FUNC void luaC_freeallobjects (lua_State *L); 136 | LUAI_FUNC void luaC_step (lua_State *L); 137 | LUAI_FUNC void luaC_runtilstate (lua_State *L, int statesmask); 138 | LUAI_FUNC void luaC_fullgc (lua_State *L, int isemergency); 139 | LUAI_FUNC GCObject *luaC_newobj (lua_State *L, int tt, size_t sz); 140 | LUAI_FUNC void luaC_barrier_ (lua_State *L, GCObject *o, GCObject *v); 141 | LUAI_FUNC void luaC_barrierback_ (lua_State *L, Table *o); 142 | LUAI_FUNC void luaC_upvalbarrier_ (lua_State *L, UpVal *uv); 143 | LUAI_FUNC void luaC_checkfinalizer (lua_State *L, GCObject *o, Table *mt); 144 | LUAI_FUNC void luaC_upvdeccount (lua_State *L, UpVal *uv); 145 | 146 | 147 | #endif 148 | -------------------------------------------------------------------------------- /src/lua-5.3.5/src/linit.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: linit.c,v 1.39.1.1 2017/04/19 17:20:42 roberto Exp $ 3 | ** Initialization of libraries for lua.c and other clients 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | 8 | #define linit_c 9 | #define LUA_LIB 10 | 11 | /* 12 | ** If you embed Lua in your program and need to open the standard 13 | ** libraries, call luaL_openlibs in your program. If you need a 14 | ** different set of libraries, copy this file to your project and edit 15 | ** it to suit your needs. 16 | ** 17 | ** You can also *preload* libraries, so that a later 'require' can 18 | ** open the library, which is already linked to the application. 19 | ** For that, do the following code: 20 | ** 21 | ** luaL_getsubtable(L, LUA_REGISTRYINDEX, LUA_PRELOAD_TABLE); 22 | ** lua_pushcfunction(L, luaopen_modname); 23 | ** lua_setfield(L, -2, modname); 24 | ** lua_pop(L, 1); // remove PRELOAD table 25 | */ 26 | 27 | #include "lprefix.h" 28 | 29 | 30 | #include 31 | 32 | #include "lua.h" 33 | 34 | #include "lualib.h" 35 | #include "lauxlib.h" 36 | 37 | 38 | /* 39 | ** these libs are loaded by lua.c and are readily available to any Lua 40 | ** program 41 | */ 42 | static const luaL_Reg loadedlibs[] = { 43 | {"_G", luaopen_base}, 44 | {LUA_LOADLIBNAME, luaopen_package}, 45 | {LUA_COLIBNAME, luaopen_coroutine}, 46 | {LUA_TABLIBNAME, luaopen_table}, 47 | {LUA_IOLIBNAME, luaopen_io}, 48 | {LUA_OSLIBNAME, luaopen_os}, 49 | {LUA_STRLIBNAME, luaopen_string}, 50 | {LUA_MATHLIBNAME, luaopen_math}, 51 | {LUA_UTF8LIBNAME, luaopen_utf8}, 52 | {LUA_DBLIBNAME, luaopen_debug}, 53 | #if defined(LUA_COMPAT_BITLIB) 54 | {LUA_BITLIBNAME, luaopen_bit32}, 55 | #endif 56 | {NULL, NULL} 57 | }; 58 | 59 | 60 | LUALIB_API void luaL_openlibs (lua_State *L) { 61 | const luaL_Reg *lib; 62 | /* "require" functions from 'loadedlibs' and set results to global table */ 63 | for (lib = loadedlibs; lib->func; lib++) { 64 | luaL_requiref(L, lib->name, lib->func, 1); 65 | lua_pop(L, 1); /* remove lib */ 66 | } 67 | } 68 | 69 | -------------------------------------------------------------------------------- /src/lua-5.3.5/src/llex.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: llex.h,v 1.79.1.1 2017/04/19 17:20:42 roberto Exp $ 3 | ** Lexical Analyzer 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef llex_h 8 | #define llex_h 9 | 10 | #include "lobject.h" 11 | #include "lzio.h" 12 | 13 | 14 | #define FIRST_RESERVED 257 15 | 16 | 17 | #if !defined(LUA_ENV) 18 | #define LUA_ENV "_ENV" 19 | #endif 20 | 21 | 22 | /* 23 | * WARNING: if you change the order of this enumeration, 24 | * grep "ORDER RESERVED" 25 | */ 26 | enum RESERVED { 27 | /* terminal symbols denoted by reserved words */ 28 | TK_AND = FIRST_RESERVED, TK_BREAK, 29 | TK_DO, TK_ELSE, TK_ELSEIF, TK_END, TK_FALSE, TK_FOR, TK_FUNCTION, 30 | TK_GOTO, TK_IF, TK_IN, TK_LOCAL, TK_NIL, TK_NOT, TK_OR, TK_REPEAT, 31 | TK_RETURN, TK_THEN, TK_TRUE, TK_UNTIL, TK_WHILE, 32 | /* other terminal symbols */ 33 | TK_IDIV, TK_CONCAT, TK_DOTS, TK_EQ, TK_GE, TK_LE, TK_NE, 34 | TK_SHL, TK_SHR, 35 | TK_DBCOLON, TK_EOS, 36 | TK_FLT, TK_INT, TK_NAME, TK_STRING 37 | }; 38 | 39 | /* number of reserved words */ 40 | #define NUM_RESERVED (cast(int, TK_WHILE-FIRST_RESERVED+1)) 41 | 42 | 43 | typedef union { 44 | lua_Number r; 45 | lua_Integer i; 46 | TString *ts; 47 | } SemInfo; /* semantics information */ 48 | 49 | 50 | typedef struct Token { 51 | int token; 52 | SemInfo seminfo; 53 | } Token; 54 | 55 | 56 | /* state of the lexer plus state of the parser when shared by all 57 | functions */ 58 | typedef struct LexState { 59 | int current; /* current character (charint) */ 60 | int linenumber; /* input line counter */ 61 | int lastline; /* line of last token 'consumed' */ 62 | Token t; /* current token */ 63 | Token lookahead; /* look ahead token */ 64 | struct FuncState *fs; /* current function (parser) */ 65 | struct lua_State *L; 66 | ZIO *z; /* input stream */ 67 | Mbuffer *buff; /* buffer for tokens */ 68 | Table *h; /* to avoid collection/reuse strings */ 69 | struct Dyndata *dyd; /* dynamic structures used by the parser */ 70 | TString *source; /* current source name */ 71 | TString *envn; /* environment variable name */ 72 | } LexState; 73 | 74 | 75 | LUAI_FUNC void luaX_init (lua_State *L); 76 | LUAI_FUNC void luaX_setinput (lua_State *L, LexState *ls, ZIO *z, 77 | TString *source, int firstchar); 78 | LUAI_FUNC TString *luaX_newstring (LexState *ls, const char *str, size_t l); 79 | LUAI_FUNC void luaX_next (LexState *ls); 80 | LUAI_FUNC int luaX_lookahead (LexState *ls); 81 | LUAI_FUNC l_noret luaX_syntaxerror (LexState *ls, const char *s); 82 | LUAI_FUNC const char *luaX_token2str (LexState *ls, int token); 83 | 84 | 85 | #endif 86 | -------------------------------------------------------------------------------- /src/lua-5.3.5/src/lmem.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lmem.c,v 1.91.1.1 2017/04/19 17:20:42 roberto Exp $ 3 | ** Interface to Memory Manager 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #define lmem_c 8 | #define LUA_CORE 9 | 10 | #include "lprefix.h" 11 | 12 | 13 | #include 14 | 15 | #include "lua.h" 16 | 17 | #include "ldebug.h" 18 | #include "ldo.h" 19 | #include "lgc.h" 20 | #include "lmem.h" 21 | #include "lobject.h" 22 | #include "lstate.h" 23 | 24 | 25 | 26 | /* 27 | ** About the realloc function: 28 | ** void * frealloc (void *ud, void *ptr, size_t osize, size_t nsize); 29 | ** ('osize' is the old size, 'nsize' is the new size) 30 | ** 31 | ** * frealloc(ud, NULL, x, s) creates a new block of size 's' (no 32 | ** matter 'x'). 33 | ** 34 | ** * frealloc(ud, p, x, 0) frees the block 'p' 35 | ** (in this specific case, frealloc must return NULL); 36 | ** particularly, frealloc(ud, NULL, 0, 0) does nothing 37 | ** (which is equivalent to free(NULL) in ISO C) 38 | ** 39 | ** frealloc returns NULL if it cannot create or reallocate the area 40 | ** (any reallocation to an equal or smaller size cannot fail!) 41 | */ 42 | 43 | 44 | 45 | #define MINSIZEARRAY 4 46 | 47 | 48 | void *luaM_growaux_ (lua_State *L, void *block, int *size, size_t size_elems, 49 | int limit, const char *what) { 50 | void *newblock; 51 | int newsize; 52 | if (*size >= limit/2) { /* cannot double it? */ 53 | if (*size >= limit) /* cannot grow even a little? */ 54 | luaG_runerror(L, "too many %s (limit is %d)", what, limit); 55 | newsize = limit; /* still have at least one free place */ 56 | } 57 | else { 58 | newsize = (*size)*2; 59 | if (newsize < MINSIZEARRAY) 60 | newsize = MINSIZEARRAY; /* minimum size */ 61 | } 62 | newblock = luaM_reallocv(L, block, *size, newsize, size_elems); 63 | *size = newsize; /* update only when everything else is OK */ 64 | return newblock; 65 | } 66 | 67 | 68 | l_noret luaM_toobig (lua_State *L) { 69 | luaG_runerror(L, "memory allocation error: block too big"); 70 | } 71 | 72 | 73 | 74 | /* 75 | ** generic allocation routine. 76 | */ 77 | void *luaM_realloc_ (lua_State *L, void *block, size_t osize, size_t nsize) { 78 | void *newblock; 79 | global_State *g = G(L); 80 | size_t realosize = (block) ? osize : 0; 81 | lua_assert((realosize == 0) == (block == NULL)); 82 | #if defined(HARDMEMTESTS) 83 | if (nsize > realosize && g->gcrunning) 84 | luaC_fullgc(L, 1); /* force a GC whenever possible */ 85 | #endif 86 | newblock = (*g->frealloc)(g->ud, block, osize, nsize); 87 | if (newblock == NULL && nsize > 0) { 88 | lua_assert(nsize > realosize); /* cannot fail when shrinking a block */ 89 | if (g->version) { /* is state fully built? */ 90 | luaC_fullgc(L, 1); /* try to free some memory... */ 91 | newblock = (*g->frealloc)(g->ud, block, osize, nsize); /* try again */ 92 | } 93 | if (newblock == NULL) 94 | luaD_throw(L, LUA_ERRMEM); 95 | } 96 | lua_assert((nsize == 0) == (newblock == NULL)); 97 | g->GCdebt = (g->GCdebt + nsize) - realosize; 98 | return newblock; 99 | } 100 | 101 | -------------------------------------------------------------------------------- /src/lua-5.3.5/src/lmem.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lmem.h,v 1.43.1.1 2017/04/19 17:20:42 roberto Exp $ 3 | ** Interface to Memory Manager 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef lmem_h 8 | #define lmem_h 9 | 10 | 11 | #include 12 | 13 | #include "llimits.h" 14 | #include "lua.h" 15 | 16 | 17 | /* 18 | ** This macro reallocs a vector 'b' from 'on' to 'n' elements, where 19 | ** each element has size 'e'. In case of arithmetic overflow of the 20 | ** product 'n'*'e', it raises an error (calling 'luaM_toobig'). Because 21 | ** 'e' is always constant, it avoids the runtime division MAX_SIZET/(e). 22 | ** 23 | ** (The macro is somewhat complex to avoid warnings: The 'sizeof' 24 | ** comparison avoids a runtime comparison when overflow cannot occur. 25 | ** The compiler should be able to optimize the real test by itself, but 26 | ** when it does it, it may give a warning about "comparison is always 27 | ** false due to limited range of data type"; the +1 tricks the compiler, 28 | ** avoiding this warning but also this optimization.) 29 | */ 30 | #define luaM_reallocv(L,b,on,n,e) \ 31 | (((sizeof(n) >= sizeof(size_t) && cast(size_t, (n)) + 1 > MAX_SIZET/(e)) \ 32 | ? luaM_toobig(L) : cast_void(0)) , \ 33 | luaM_realloc_(L, (b), (on)*(e), (n)*(e))) 34 | 35 | /* 36 | ** Arrays of chars do not need any test 37 | */ 38 | #define luaM_reallocvchar(L,b,on,n) \ 39 | cast(char *, luaM_realloc_(L, (b), (on)*sizeof(char), (n)*sizeof(char))) 40 | 41 | #define luaM_freemem(L, b, s) luaM_realloc_(L, (b), (s), 0) 42 | #define luaM_free(L, b) luaM_realloc_(L, (b), sizeof(*(b)), 0) 43 | #define luaM_freearray(L, b, n) luaM_realloc_(L, (b), (n)*sizeof(*(b)), 0) 44 | 45 | #define luaM_malloc(L,s) luaM_realloc_(L, NULL, 0, (s)) 46 | #define luaM_new(L,t) cast(t *, luaM_malloc(L, sizeof(t))) 47 | #define luaM_newvector(L,n,t) \ 48 | cast(t *, luaM_reallocv(L, NULL, 0, n, sizeof(t))) 49 | 50 | #define luaM_newobject(L,tag,s) luaM_realloc_(L, NULL, tag, (s)) 51 | 52 | #define luaM_growvector(L,v,nelems,size,t,limit,e) \ 53 | if ((nelems)+1 > (size)) \ 54 | ((v)=cast(t *, luaM_growaux_(L,v,&(size),sizeof(t),limit,e))) 55 | 56 | #define luaM_reallocvector(L, v,oldn,n,t) \ 57 | ((v)=cast(t *, luaM_reallocv(L, v, oldn, n, sizeof(t)))) 58 | 59 | LUAI_FUNC l_noret luaM_toobig (lua_State *L); 60 | 61 | /* not to be called directly */ 62 | LUAI_FUNC void *luaM_realloc_ (lua_State *L, void *block, size_t oldsize, 63 | size_t size); 64 | LUAI_FUNC void *luaM_growaux_ (lua_State *L, void *block, int *size, 65 | size_t size_elem, int limit, 66 | const char *what); 67 | 68 | #endif 69 | 70 | -------------------------------------------------------------------------------- /src/lua-5.3.5/src/lopcodes.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lopcodes.c,v 1.55.1.1 2017/04/19 17:20:42 roberto Exp $ 3 | ** Opcodes for Lua virtual machine 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #define lopcodes_c 8 | #define LUA_CORE 9 | 10 | #include "lprefix.h" 11 | 12 | 13 | #include 14 | 15 | #include "lopcodes.h" 16 | 17 | 18 | /* ORDER OP */ 19 | 20 | LUAI_DDEF const char *const luaP_opnames[NUM_OPCODES+1] = { 21 | "MOVE", 22 | "LOADK", 23 | "LOADKX", 24 | "LOADBOOL", 25 | "LOADNIL", 26 | "GETUPVAL", 27 | "GETTABUP", 28 | "GETTABLE", 29 | "SETTABUP", 30 | "SETUPVAL", 31 | "SETTABLE", 32 | "NEWTABLE", 33 | "SELF", 34 | "ADD", 35 | "SUB", 36 | "MUL", 37 | "MOD", 38 | "POW", 39 | "DIV", 40 | "IDIV", 41 | "BAND", 42 | "BOR", 43 | "BXOR", 44 | "SHL", 45 | "SHR", 46 | "UNM", 47 | "BNOT", 48 | "NOT", 49 | "LEN", 50 | "CONCAT", 51 | "JMP", 52 | "EQ", 53 | "LT", 54 | "LE", 55 | "TEST", 56 | "TESTSET", 57 | "CALL", 58 | "TAILCALL", 59 | "RETURN", 60 | "FORLOOP", 61 | "FORPREP", 62 | "TFORCALL", 63 | "TFORLOOP", 64 | "SETLIST", 65 | "CLOSURE", 66 | "VARARG", 67 | "EXTRAARG", 68 | NULL 69 | }; 70 | 71 | 72 | #define opmode(t,a,b,c,m) (((t)<<7) | ((a)<<6) | ((b)<<4) | ((c)<<2) | (m)) 73 | 74 | LUAI_DDEF const lu_byte luaP_opmodes[NUM_OPCODES] = { 75 | /* T A B C mode opcode */ 76 | opmode(0, 1, OpArgR, OpArgN, iABC) /* OP_MOVE */ 77 | ,opmode(0, 1, OpArgK, OpArgN, iABx) /* OP_LOADK */ 78 | ,opmode(0, 1, OpArgN, OpArgN, iABx) /* OP_LOADKX */ 79 | ,opmode(0, 1, OpArgU, OpArgU, iABC) /* OP_LOADBOOL */ 80 | ,opmode(0, 1, OpArgU, OpArgN, iABC) /* OP_LOADNIL */ 81 | ,opmode(0, 1, OpArgU, OpArgN, iABC) /* OP_GETUPVAL */ 82 | ,opmode(0, 1, OpArgU, OpArgK, iABC) /* OP_GETTABUP */ 83 | ,opmode(0, 1, OpArgR, OpArgK, iABC) /* OP_GETTABLE */ 84 | ,opmode(0, 0, OpArgK, OpArgK, iABC) /* OP_SETTABUP */ 85 | ,opmode(0, 0, OpArgU, OpArgN, iABC) /* OP_SETUPVAL */ 86 | ,opmode(0, 0, OpArgK, OpArgK, iABC) /* OP_SETTABLE */ 87 | ,opmode(0, 1, OpArgU, OpArgU, iABC) /* OP_NEWTABLE */ 88 | ,opmode(0, 1, OpArgR, OpArgK, iABC) /* OP_SELF */ 89 | ,opmode(0, 1, OpArgK, OpArgK, iABC) /* OP_ADD */ 90 | ,opmode(0, 1, OpArgK, OpArgK, iABC) /* OP_SUB */ 91 | ,opmode(0, 1, OpArgK, OpArgK, iABC) /* OP_MUL */ 92 | ,opmode(0, 1, OpArgK, OpArgK, iABC) /* OP_MOD */ 93 | ,opmode(0, 1, OpArgK, OpArgK, iABC) /* OP_POW */ 94 | ,opmode(0, 1, OpArgK, OpArgK, iABC) /* OP_DIV */ 95 | ,opmode(0, 1, OpArgK, OpArgK, iABC) /* OP_IDIV */ 96 | ,opmode(0, 1, OpArgK, OpArgK, iABC) /* OP_BAND */ 97 | ,opmode(0, 1, OpArgK, OpArgK, iABC) /* OP_BOR */ 98 | ,opmode(0, 1, OpArgK, OpArgK, iABC) /* OP_BXOR */ 99 | ,opmode(0, 1, OpArgK, OpArgK, iABC) /* OP_SHL */ 100 | ,opmode(0, 1, OpArgK, OpArgK, iABC) /* OP_SHR */ 101 | ,opmode(0, 1, OpArgR, OpArgN, iABC) /* OP_UNM */ 102 | ,opmode(0, 1, OpArgR, OpArgN, iABC) /* OP_BNOT */ 103 | ,opmode(0, 1, OpArgR, OpArgN, iABC) /* OP_NOT */ 104 | ,opmode(0, 1, OpArgR, OpArgN, iABC) /* OP_LEN */ 105 | ,opmode(0, 1, OpArgR, OpArgR, iABC) /* OP_CONCAT */ 106 | ,opmode(0, 0, OpArgR, OpArgN, iAsBx) /* OP_JMP */ 107 | ,opmode(1, 0, OpArgK, OpArgK, iABC) /* OP_EQ */ 108 | ,opmode(1, 0, OpArgK, OpArgK, iABC) /* OP_LT */ 109 | ,opmode(1, 0, OpArgK, OpArgK, iABC) /* OP_LE */ 110 | ,opmode(1, 0, OpArgN, OpArgU, iABC) /* OP_TEST */ 111 | ,opmode(1, 1, OpArgR, OpArgU, iABC) /* OP_TESTSET */ 112 | ,opmode(0, 1, OpArgU, OpArgU, iABC) /* OP_CALL */ 113 | ,opmode(0, 1, OpArgU, OpArgU, iABC) /* OP_TAILCALL */ 114 | ,opmode(0, 0, OpArgU, OpArgN, iABC) /* OP_RETURN */ 115 | ,opmode(0, 1, OpArgR, OpArgN, iAsBx) /* OP_FORLOOP */ 116 | ,opmode(0, 1, OpArgR, OpArgN, iAsBx) /* OP_FORPREP */ 117 | ,opmode(0, 0, OpArgN, OpArgU, iABC) /* OP_TFORCALL */ 118 | ,opmode(0, 1, OpArgR, OpArgN, iAsBx) /* OP_TFORLOOP */ 119 | ,opmode(0, 0, OpArgU, OpArgU, iABC) /* OP_SETLIST */ 120 | ,opmode(0, 1, OpArgU, OpArgN, iABx) /* OP_CLOSURE */ 121 | ,opmode(0, 1, OpArgU, OpArgN, iABC) /* OP_VARARG */ 122 | ,opmode(0, 0, OpArgU, OpArgU, iAx) /* OP_EXTRAARG */ 123 | }; 124 | 125 | -------------------------------------------------------------------------------- /src/lua-5.3.5/src/lparser.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lparser.h,v 1.76.1.1 2017/04/19 17:20:42 roberto Exp $ 3 | ** Lua Parser 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef lparser_h 8 | #define lparser_h 9 | 10 | #include "llimits.h" 11 | #include "lobject.h" 12 | #include "lzio.h" 13 | 14 | 15 | /* 16 | ** Expression and variable descriptor. 17 | ** Code generation for variables and expressions can be delayed to allow 18 | ** optimizations; An 'expdesc' structure describes a potentially-delayed 19 | ** variable/expression. It has a description of its "main" value plus a 20 | ** list of conditional jumps that can also produce its value (generated 21 | ** by short-circuit operators 'and'/'or'). 22 | */ 23 | 24 | /* kinds of variables/expressions */ 25 | typedef enum { 26 | VVOID, /* when 'expdesc' describes the last expression a list, 27 | this kind means an empty list (so, no expression) */ 28 | VNIL, /* constant nil */ 29 | VTRUE, /* constant true */ 30 | VFALSE, /* constant false */ 31 | VK, /* constant in 'k'; info = index of constant in 'k' */ 32 | VKFLT, /* floating constant; nval = numerical float value */ 33 | VKINT, /* integer constant; nval = numerical integer value */ 34 | VNONRELOC, /* expression has its value in a fixed register; 35 | info = result register */ 36 | VLOCAL, /* local variable; info = local register */ 37 | VUPVAL, /* upvalue variable; info = index of upvalue in 'upvalues' */ 38 | VINDEXED, /* indexed variable; 39 | ind.vt = whether 't' is register or upvalue; 40 | ind.t = table register or upvalue; 41 | ind.idx = key's R/K index */ 42 | VJMP, /* expression is a test/comparison; 43 | info = pc of corresponding jump instruction */ 44 | VRELOCABLE, /* expression can put result in any register; 45 | info = instruction pc */ 46 | VCALL, /* expression is a function call; info = instruction pc */ 47 | VVARARG /* vararg expression; info = instruction pc */ 48 | } expkind; 49 | 50 | 51 | #define vkisvar(k) (VLOCAL <= (k) && (k) <= VINDEXED) 52 | #define vkisinreg(k) ((k) == VNONRELOC || (k) == VLOCAL) 53 | 54 | typedef struct expdesc { 55 | expkind k; 56 | union { 57 | lua_Integer ival; /* for VKINT */ 58 | lua_Number nval; /* for VKFLT */ 59 | int info; /* for generic use */ 60 | struct { /* for indexed variables (VINDEXED) */ 61 | short idx; /* index (R/K) */ 62 | lu_byte t; /* table (register or upvalue) */ 63 | lu_byte vt; /* whether 't' is register (VLOCAL) or upvalue (VUPVAL) */ 64 | } ind; 65 | } u; 66 | int t; /* patch list of 'exit when true' */ 67 | int f; /* patch list of 'exit when false' */ 68 | } expdesc; 69 | 70 | 71 | /* description of active local variable */ 72 | typedef struct Vardesc { 73 | short idx; /* variable index in stack */ 74 | } Vardesc; 75 | 76 | 77 | /* description of pending goto statements and label statements */ 78 | typedef struct Labeldesc { 79 | TString *name; /* label identifier */ 80 | int pc; /* position in code */ 81 | int line; /* line where it appeared */ 82 | lu_byte nactvar; /* local level where it appears in current block */ 83 | } Labeldesc; 84 | 85 | 86 | /* list of labels or gotos */ 87 | typedef struct Labellist { 88 | Labeldesc *arr; /* array */ 89 | int n; /* number of entries in use */ 90 | int size; /* array size */ 91 | } Labellist; 92 | 93 | 94 | /* dynamic structures used by the parser */ 95 | typedef struct Dyndata { 96 | struct { /* list of active local variables */ 97 | Vardesc *arr; 98 | int n; 99 | int size; 100 | } actvar; 101 | Labellist gt; /* list of pending gotos */ 102 | Labellist label; /* list of active labels */ 103 | } Dyndata; 104 | 105 | 106 | /* control of blocks */ 107 | struct BlockCnt; /* defined in lparser.c */ 108 | 109 | 110 | /* state needed to generate code for a given function */ 111 | typedef struct FuncState { 112 | Proto *f; /* current function header */ 113 | struct FuncState *prev; /* enclosing function */ 114 | struct LexState *ls; /* lexical state */ 115 | struct BlockCnt *bl; /* chain of current blocks */ 116 | int pc; /* next position to code (equivalent to 'ncode') */ 117 | int lasttarget; /* 'label' of last 'jump label' */ 118 | int jpc; /* list of pending jumps to 'pc' */ 119 | int nk; /* number of elements in 'k' */ 120 | int np; /* number of elements in 'p' */ 121 | int firstlocal; /* index of first local var (in Dyndata array) */ 122 | short nlocvars; /* number of elements in 'f->locvars' */ 123 | lu_byte nactvar; /* number of active local variables */ 124 | lu_byte nups; /* number of upvalues */ 125 | lu_byte freereg; /* first free register */ 126 | } FuncState; 127 | 128 | 129 | LUAI_FUNC LClosure *luaY_parser (lua_State *L, ZIO *z, Mbuffer *buff, 130 | Dyndata *dyd, const char *name, int firstchar); 131 | 132 | 133 | #endif 134 | -------------------------------------------------------------------------------- /src/lua-5.3.5/src/lprefix.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lprefix.h,v 1.2.1.1 2017/04/19 17:20:42 roberto Exp $ 3 | ** Definitions for Lua code that must come before any other header file 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef lprefix_h 8 | #define lprefix_h 9 | 10 | 11 | /* 12 | ** Allows POSIX/XSI stuff 13 | */ 14 | #if !defined(LUA_USE_C89) /* { */ 15 | 16 | #if !defined(_XOPEN_SOURCE) 17 | #define _XOPEN_SOURCE 600 18 | #elif _XOPEN_SOURCE == 0 19 | #undef _XOPEN_SOURCE /* use -D_XOPEN_SOURCE=0 to undefine it */ 20 | #endif 21 | 22 | /* 23 | ** Allows manipulation of large files in gcc and some other compilers 24 | */ 25 | #if !defined(LUA_32BITS) && !defined(_FILE_OFFSET_BITS) 26 | #define _LARGEFILE_SOURCE 1 27 | #define _FILE_OFFSET_BITS 64 28 | #endif 29 | 30 | #endif /* } */ 31 | 32 | 33 | /* 34 | ** Windows stuff 35 | */ 36 | #if defined(_WIN32) /* { */ 37 | 38 | #if !defined(_CRT_SECURE_NO_WARNINGS) 39 | #define _CRT_SECURE_NO_WARNINGS /* avoid warnings about ISO C functions */ 40 | #endif 41 | 42 | #endif /* } */ 43 | 44 | #endif 45 | 46 | -------------------------------------------------------------------------------- /src/lua-5.3.5/src/lstring.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lstring.h,v 1.61.1.1 2017/04/19 17:20:42 roberto Exp $ 3 | ** String table (keep all strings handled by Lua) 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef lstring_h 8 | #define lstring_h 9 | 10 | #include "lgc.h" 11 | #include "lobject.h" 12 | #include "lstate.h" 13 | 14 | 15 | #define sizelstring(l) (sizeof(union UTString) + ((l) + 1) * sizeof(char)) 16 | 17 | #define sizeludata(l) (sizeof(union UUdata) + (l)) 18 | #define sizeudata(u) sizeludata((u)->len) 19 | 20 | #define luaS_newliteral(L, s) (luaS_newlstr(L, "" s, \ 21 | (sizeof(s)/sizeof(char))-1)) 22 | 23 | 24 | /* 25 | ** test whether a string is a reserved word 26 | */ 27 | #define isreserved(s) ((s)->tt == LUA_TSHRSTR && (s)->extra > 0) 28 | 29 | 30 | /* 31 | ** equality for short strings, which are always internalized 32 | */ 33 | #define eqshrstr(a,b) check_exp((a)->tt == LUA_TSHRSTR, (a) == (b)) 34 | 35 | 36 | LUAI_FUNC unsigned int luaS_hash (const char *str, size_t l, unsigned int seed); 37 | LUAI_FUNC unsigned int luaS_hashlongstr (TString *ts); 38 | LUAI_FUNC int luaS_eqlngstr (TString *a, TString *b); 39 | LUAI_FUNC void luaS_resize (lua_State *L, int newsize); 40 | LUAI_FUNC void luaS_clearcache (global_State *g); 41 | LUAI_FUNC void luaS_init (lua_State *L); 42 | LUAI_FUNC void luaS_remove (lua_State *L, TString *ts); 43 | LUAI_FUNC Udata *luaS_newudata (lua_State *L, size_t s); 44 | LUAI_FUNC TString *luaS_newlstr (lua_State *L, const char *str, size_t l); 45 | LUAI_FUNC TString *luaS_new (lua_State *L, const char *str); 46 | LUAI_FUNC TString *luaS_createlngstrobj (lua_State *L, size_t l); 47 | 48 | 49 | #endif 50 | -------------------------------------------------------------------------------- /src/lua-5.3.5/src/ltable.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: ltable.h,v 2.23.1.2 2018/05/24 19:39:05 roberto Exp $ 3 | ** Lua tables (hash) 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef ltable_h 8 | #define ltable_h 9 | 10 | #include "lobject.h" 11 | 12 | 13 | #define gnode(t,i) (&(t)->node[i]) 14 | #define gval(n) (&(n)->i_val) 15 | #define gnext(n) ((n)->i_key.nk.next) 16 | 17 | 18 | /* 'const' to avoid wrong writings that can mess up field 'next' */ 19 | #define gkey(n) cast(const TValue*, (&(n)->i_key.tvk)) 20 | 21 | /* 22 | ** writable version of 'gkey'; allows updates to individual fields, 23 | ** but not to the whole (which has incompatible type) 24 | */ 25 | #define wgkey(n) (&(n)->i_key.nk) 26 | 27 | #define invalidateTMcache(t) ((t)->flags = 0) 28 | 29 | 30 | /* true when 't' is using 'dummynode' as its hash part */ 31 | #define isdummy(t) ((t)->lastfree == NULL) 32 | 33 | 34 | /* allocated size for hash nodes */ 35 | #define allocsizenode(t) (isdummy(t) ? 0 : sizenode(t)) 36 | 37 | 38 | /* returns the key, given the value of a table entry */ 39 | #define keyfromval(v) \ 40 | (gkey(cast(Node *, cast(char *, (v)) - offsetof(Node, i_val)))) 41 | 42 | 43 | LUAI_FUNC const TValue *luaH_getint (Table *t, lua_Integer key); 44 | LUAI_FUNC void luaH_setint (lua_State *L, Table *t, lua_Integer key, 45 | TValue *value); 46 | LUAI_FUNC const TValue *luaH_getshortstr (Table *t, TString *key); 47 | LUAI_FUNC const TValue *luaH_getstr (Table *t, TString *key); 48 | LUAI_FUNC const TValue *luaH_get (Table *t, const TValue *key); 49 | LUAI_FUNC TValue *luaH_newkey (lua_State *L, Table *t, const TValue *key); 50 | LUAI_FUNC TValue *luaH_set (lua_State *L, Table *t, const TValue *key); 51 | LUAI_FUNC Table *luaH_new (lua_State *L); 52 | LUAI_FUNC void luaH_resize (lua_State *L, Table *t, unsigned int nasize, 53 | unsigned int nhsize); 54 | LUAI_FUNC void luaH_resizearray (lua_State *L, Table *t, unsigned int nasize); 55 | LUAI_FUNC void luaH_free (lua_State *L, Table *t); 56 | LUAI_FUNC int luaH_next (lua_State *L, Table *t, StkId key); 57 | LUAI_FUNC lua_Unsigned luaH_getn (Table *t); 58 | 59 | 60 | #if defined(LUA_DEBUG) 61 | LUAI_FUNC Node *luaH_mainposition (const Table *t, const TValue *key); 62 | LUAI_FUNC int luaH_isdummy (const Table *t); 63 | #endif 64 | 65 | 66 | #endif 67 | -------------------------------------------------------------------------------- /src/lua-5.3.5/src/ltm.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: ltm.c,v 2.38.1.1 2017/04/19 17:39:34 roberto Exp $ 3 | ** Tag methods 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #define ltm_c 8 | #define LUA_CORE 9 | 10 | #include "lprefix.h" 11 | 12 | 13 | #include 14 | 15 | #include "lua.h" 16 | 17 | #include "ldebug.h" 18 | #include "ldo.h" 19 | #include "lobject.h" 20 | #include "lstate.h" 21 | #include "lstring.h" 22 | #include "ltable.h" 23 | #include "ltm.h" 24 | #include "lvm.h" 25 | 26 | 27 | static const char udatatypename[] = "userdata"; 28 | 29 | LUAI_DDEF const char *const luaT_typenames_[LUA_TOTALTAGS] = { 30 | "no value", 31 | "nil", "boolean", udatatypename, "number", 32 | "string", "table", "function", udatatypename, "thread", 33 | "proto" /* this last case is used for tests only */ 34 | }; 35 | 36 | 37 | void luaT_init (lua_State *L) { 38 | static const char *const luaT_eventname[] = { /* ORDER TM */ 39 | "__index", "__newindex", 40 | "__gc", "__mode", "__len", "__eq", 41 | "__add", "__sub", "__mul", "__mod", "__pow", 42 | "__div", "__idiv", 43 | "__band", "__bor", "__bxor", "__shl", "__shr", 44 | "__unm", "__bnot", "__lt", "__le", 45 | "__concat", "__call" 46 | }; 47 | int i; 48 | for (i=0; itmname[i] = luaS_new(L, luaT_eventname[i]); 50 | luaC_fix(L, obj2gco(G(L)->tmname[i])); /* never collect these names */ 51 | } 52 | } 53 | 54 | 55 | /* 56 | ** function to be used with macro "fasttm": optimized for absence of 57 | ** tag methods 58 | */ 59 | const TValue *luaT_gettm (Table *events, TMS event, TString *ename) { 60 | const TValue *tm = luaH_getshortstr(events, ename); 61 | lua_assert(event <= TM_EQ); 62 | if (ttisnil(tm)) { /* no tag method? */ 63 | events->flags |= cast_byte(1u<metatable; 75 | break; 76 | case LUA_TUSERDATA: 77 | mt = uvalue(o)->metatable; 78 | break; 79 | default: 80 | mt = G(L)->mt[ttnov(o)]; 81 | } 82 | return (mt ? luaH_getshortstr(mt, G(L)->tmname[event]) : luaO_nilobject); 83 | } 84 | 85 | 86 | /* 87 | ** Return the name of the type of an object. For tables and userdata 88 | ** with metatable, use their '__name' metafield, if present. 89 | */ 90 | const char *luaT_objtypename (lua_State *L, const TValue *o) { 91 | Table *mt; 92 | if ((ttistable(o) && (mt = hvalue(o)->metatable) != NULL) || 93 | (ttisfulluserdata(o) && (mt = uvalue(o)->metatable) != NULL)) { 94 | const TValue *name = luaH_getshortstr(mt, luaS_new(L, "__name")); 95 | if (ttisstring(name)) /* is '__name' a string? */ 96 | return getstr(tsvalue(name)); /* use it as type name */ 97 | } 98 | return ttypename(ttnov(o)); /* else use standard type name */ 99 | } 100 | 101 | 102 | void luaT_callTM (lua_State *L, const TValue *f, const TValue *p1, 103 | const TValue *p2, TValue *p3, int hasres) { 104 | ptrdiff_t result = savestack(L, p3); 105 | StkId func = L->top; 106 | setobj2s(L, func, f); /* push function (assume EXTRA_STACK) */ 107 | setobj2s(L, func + 1, p1); /* 1st argument */ 108 | setobj2s(L, func + 2, p2); /* 2nd argument */ 109 | L->top += 3; 110 | if (!hasres) /* no result? 'p3' is third argument */ 111 | setobj2s(L, L->top++, p3); /* 3rd argument */ 112 | /* metamethod may yield only when called from Lua code */ 113 | if (isLua(L->ci)) 114 | luaD_call(L, func, hasres); 115 | else 116 | luaD_callnoyield(L, func, hasres); 117 | if (hasres) { /* if has result, move it to its place */ 118 | p3 = restorestack(L, result); 119 | setobjs2s(L, p3, --L->top); 120 | } 121 | } 122 | 123 | 124 | int luaT_callbinTM (lua_State *L, const TValue *p1, const TValue *p2, 125 | StkId res, TMS event) { 126 | const TValue *tm = luaT_gettmbyobj(L, p1, event); /* try first operand */ 127 | if (ttisnil(tm)) 128 | tm = luaT_gettmbyobj(L, p2, event); /* try second operand */ 129 | if (ttisnil(tm)) return 0; 130 | luaT_callTM(L, tm, p1, p2, res, 1); 131 | return 1; 132 | } 133 | 134 | 135 | void luaT_trybinTM (lua_State *L, const TValue *p1, const TValue *p2, 136 | StkId res, TMS event) { 137 | if (!luaT_callbinTM(L, p1, p2, res, event)) { 138 | switch (event) { 139 | case TM_CONCAT: 140 | luaG_concaterror(L, p1, p2); 141 | /* call never returns, but to avoid warnings: *//* FALLTHROUGH */ 142 | case TM_BAND: case TM_BOR: case TM_BXOR: 143 | case TM_SHL: case TM_SHR: case TM_BNOT: { 144 | lua_Number dummy; 145 | if (tonumber(p1, &dummy) && tonumber(p2, &dummy)) 146 | luaG_tointerror(L, p1, p2); 147 | else 148 | luaG_opinterror(L, p1, p2, "perform bitwise operation on"); 149 | } 150 | /* calls never return, but to avoid warnings: *//* FALLTHROUGH */ 151 | default: 152 | luaG_opinterror(L, p1, p2, "perform arithmetic on"); 153 | } 154 | } 155 | } 156 | 157 | 158 | int luaT_callorderTM (lua_State *L, const TValue *p1, const TValue *p2, 159 | TMS event) { 160 | if (!luaT_callbinTM(L, p1, p2, L->top, event)) 161 | return -1; /* no metamethod */ 162 | else 163 | return !l_isfalse(L->top); 164 | } 165 | 166 | -------------------------------------------------------------------------------- /src/lua-5.3.5/src/ltm.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: ltm.h,v 2.22.1.1 2017/04/19 17:20:42 roberto Exp $ 3 | ** Tag methods 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef ltm_h 8 | #define ltm_h 9 | 10 | 11 | #include "lobject.h" 12 | 13 | 14 | /* 15 | * WARNING: if you change the order of this enumeration, 16 | * grep "ORDER TM" and "ORDER OP" 17 | */ 18 | typedef enum { 19 | TM_INDEX, 20 | TM_NEWINDEX, 21 | TM_GC, 22 | TM_MODE, 23 | TM_LEN, 24 | TM_EQ, /* last tag method with fast access */ 25 | TM_ADD, 26 | TM_SUB, 27 | TM_MUL, 28 | TM_MOD, 29 | TM_POW, 30 | TM_DIV, 31 | TM_IDIV, 32 | TM_BAND, 33 | TM_BOR, 34 | TM_BXOR, 35 | TM_SHL, 36 | TM_SHR, 37 | TM_UNM, 38 | TM_BNOT, 39 | TM_LT, 40 | TM_LE, 41 | TM_CONCAT, 42 | TM_CALL, 43 | TM_N /* number of elements in the enum */ 44 | } TMS; 45 | 46 | 47 | 48 | #define gfasttm(g,et,e) ((et) == NULL ? NULL : \ 49 | ((et)->flags & (1u<<(e))) ? NULL : luaT_gettm(et, e, (g)->tmname[e])) 50 | 51 | #define fasttm(l,et,e) gfasttm(G(l), et, e) 52 | 53 | #define ttypename(x) luaT_typenames_[(x) + 1] 54 | 55 | LUAI_DDEC const char *const luaT_typenames_[LUA_TOTALTAGS]; 56 | 57 | 58 | LUAI_FUNC const char *luaT_objtypename (lua_State *L, const TValue *o); 59 | 60 | LUAI_FUNC const TValue *luaT_gettm (Table *events, TMS event, TString *ename); 61 | LUAI_FUNC const TValue *luaT_gettmbyobj (lua_State *L, const TValue *o, 62 | TMS event); 63 | LUAI_FUNC void luaT_init (lua_State *L); 64 | 65 | LUAI_FUNC void luaT_callTM (lua_State *L, const TValue *f, const TValue *p1, 66 | const TValue *p2, TValue *p3, int hasres); 67 | LUAI_FUNC int luaT_callbinTM (lua_State *L, const TValue *p1, const TValue *p2, 68 | StkId res, TMS event); 69 | LUAI_FUNC void luaT_trybinTM (lua_State *L, const TValue *p1, const TValue *p2, 70 | StkId res, TMS event); 71 | LUAI_FUNC int luaT_callorderTM (lua_State *L, const TValue *p1, 72 | const TValue *p2, TMS event); 73 | 74 | 75 | 76 | #endif 77 | -------------------------------------------------------------------------------- /src/lua-5.3.5/src/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 | -------------------------------------------------------------------------------- /src/lua-5.3.5/src/lualib.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lualib.h,v 1.45.1.1 2017/04/19 17:20:42 roberto Exp $ 3 | ** Lua standard libraries 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | 8 | #ifndef lualib_h 9 | #define lualib_h 10 | 11 | #include "lua.h" 12 | 13 | 14 | /* version suffix for environment variable names */ 15 | #define LUA_VERSUFFIX "_" LUA_VERSION_MAJOR "_" LUA_VERSION_MINOR 16 | 17 | 18 | LUAMOD_API int (luaopen_base) (lua_State *L); 19 | 20 | #define LUA_COLIBNAME "coroutine" 21 | LUAMOD_API int (luaopen_coroutine) (lua_State *L); 22 | 23 | #define LUA_TABLIBNAME "table" 24 | LUAMOD_API int (luaopen_table) (lua_State *L); 25 | 26 | #define LUA_IOLIBNAME "io" 27 | LUAMOD_API int (luaopen_io) (lua_State *L); 28 | 29 | #define LUA_OSLIBNAME "os" 30 | LUAMOD_API int (luaopen_os) (lua_State *L); 31 | 32 | #define LUA_STRLIBNAME "string" 33 | LUAMOD_API int (luaopen_string) (lua_State *L); 34 | 35 | #define LUA_UTF8LIBNAME "utf8" 36 | LUAMOD_API int (luaopen_utf8) (lua_State *L); 37 | 38 | #define LUA_BITLIBNAME "bit32" 39 | LUAMOD_API int (luaopen_bit32) (lua_State *L); 40 | 41 | #define LUA_MATHLIBNAME "math" 42 | LUAMOD_API int (luaopen_math) (lua_State *L); 43 | 44 | #define LUA_DBLIBNAME "debug" 45 | LUAMOD_API int (luaopen_debug) (lua_State *L); 46 | 47 | #define LUA_LOADLIBNAME "package" 48 | LUAMOD_API int (luaopen_package) (lua_State *L); 49 | 50 | 51 | /* open all previous libraries */ 52 | LUALIB_API void (luaL_openlibs) (lua_State *L); 53 | 54 | 55 | 56 | #if !defined(lua_assert) 57 | #define lua_assert(x) ((void)0) 58 | #endif 59 | 60 | 61 | #endif 62 | -------------------------------------------------------------------------------- /src/lua-5.3.5/src/lundump.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lundump.c,v 2.44.1.1 2017/04/19 17:20:42 roberto Exp $ 3 | ** load precompiled Lua chunks 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #define lundump_c 8 | #define LUA_CORE 9 | 10 | #include "lprefix.h" 11 | 12 | 13 | #include 14 | 15 | #include "lua.h" 16 | 17 | #include "ldebug.h" 18 | #include "ldo.h" 19 | #include "lfunc.h" 20 | #include "lmem.h" 21 | #include "lobject.h" 22 | #include "lstring.h" 23 | #include "lundump.h" 24 | #include "lzio.h" 25 | 26 | 27 | #if !defined(luai_verifycode) 28 | #define luai_verifycode(L,b,f) /* empty */ 29 | #endif 30 | 31 | 32 | typedef struct { 33 | lua_State *L; 34 | ZIO *Z; 35 | const char *name; 36 | } LoadState; 37 | 38 | 39 | static l_noret error(LoadState *S, const char *why) { 40 | luaO_pushfstring(S->L, "%s: %s precompiled chunk", S->name, why); 41 | luaD_throw(S->L, LUA_ERRSYNTAX); 42 | } 43 | 44 | 45 | /* 46 | ** All high-level loads go through LoadVector; you can change it to 47 | ** adapt to the endianness of the input 48 | */ 49 | #define LoadVector(S,b,n) LoadBlock(S,b,(n)*sizeof((b)[0])) 50 | 51 | static void LoadBlock (LoadState *S, void *b, size_t size) { 52 | if (luaZ_read(S->Z, b, size) != 0) 53 | error(S, "truncated"); 54 | } 55 | 56 | 57 | #define LoadVar(S,x) LoadVector(S,&x,1) 58 | 59 | 60 | static lu_byte LoadByte (LoadState *S) { 61 | lu_byte x; 62 | LoadVar(S, x); 63 | return x; 64 | } 65 | 66 | 67 | static int LoadInt (LoadState *S) { 68 | int x; 69 | LoadVar(S, x); 70 | return x; 71 | } 72 | 73 | 74 | static lua_Number LoadNumber (LoadState *S) { 75 | lua_Number x; 76 | LoadVar(S, x); 77 | return x; 78 | } 79 | 80 | 81 | static lua_Integer LoadInteger (LoadState *S) { 82 | lua_Integer x; 83 | LoadVar(S, x); 84 | return x; 85 | } 86 | 87 | 88 | static TString *LoadString (LoadState *S) { 89 | size_t size = LoadByte(S); 90 | if (size == 0xFF) 91 | LoadVar(S, size); 92 | if (size == 0) 93 | return NULL; 94 | else if (--size <= LUAI_MAXSHORTLEN) { /* short string? */ 95 | char buff[LUAI_MAXSHORTLEN]; 96 | LoadVector(S, buff, size); 97 | return luaS_newlstr(S->L, buff, size); 98 | } 99 | else { /* long string */ 100 | TString *ts = luaS_createlngstrobj(S->L, size); 101 | LoadVector(S, getstr(ts), size); /* load directly in final place */ 102 | return ts; 103 | } 104 | } 105 | 106 | 107 | static void LoadCode (LoadState *S, Proto *f) { 108 | int n = LoadInt(S); 109 | f->code = luaM_newvector(S->L, n, Instruction); 110 | f->sizecode = n; 111 | LoadVector(S, f->code, n); 112 | } 113 | 114 | 115 | static void LoadFunction(LoadState *S, Proto *f, TString *psource); 116 | 117 | 118 | static void LoadConstants (LoadState *S, Proto *f) { 119 | int i; 120 | int n = LoadInt(S); 121 | f->k = luaM_newvector(S->L, n, TValue); 122 | f->sizek = n; 123 | for (i = 0; i < n; i++) 124 | setnilvalue(&f->k[i]); 125 | for (i = 0; i < n; i++) { 126 | TValue *o = &f->k[i]; 127 | int t = LoadByte(S); 128 | switch (t) { 129 | case LUA_TNIL: 130 | setnilvalue(o); 131 | break; 132 | case LUA_TBOOLEAN: 133 | setbvalue(o, LoadByte(S)); 134 | break; 135 | case LUA_TNUMFLT: 136 | setfltvalue(o, LoadNumber(S)); 137 | break; 138 | case LUA_TNUMINT: 139 | setivalue(o, LoadInteger(S)); 140 | break; 141 | case LUA_TSHRSTR: 142 | case LUA_TLNGSTR: 143 | setsvalue2n(S->L, o, LoadString(S)); 144 | break; 145 | default: 146 | lua_assert(0); 147 | } 148 | } 149 | } 150 | 151 | 152 | static void LoadProtos (LoadState *S, Proto *f) { 153 | int i; 154 | int n = LoadInt(S); 155 | f->p = luaM_newvector(S->L, n, Proto *); 156 | f->sizep = n; 157 | for (i = 0; i < n; i++) 158 | f->p[i] = NULL; 159 | for (i = 0; i < n; i++) { 160 | f->p[i] = luaF_newproto(S->L); 161 | LoadFunction(S, f->p[i], f->source); 162 | } 163 | } 164 | 165 | 166 | static void LoadUpvalues (LoadState *S, Proto *f) { 167 | int i, n; 168 | n = LoadInt(S); 169 | f->upvalues = luaM_newvector(S->L, n, Upvaldesc); 170 | f->sizeupvalues = n; 171 | for (i = 0; i < n; i++) 172 | f->upvalues[i].name = NULL; 173 | for (i = 0; i < n; i++) { 174 | f->upvalues[i].instack = LoadByte(S); 175 | f->upvalues[i].idx = LoadByte(S); 176 | } 177 | } 178 | 179 | 180 | static void LoadDebug (LoadState *S, Proto *f) { 181 | int i, n; 182 | n = LoadInt(S); 183 | f->lineinfo = luaM_newvector(S->L, n, int); 184 | f->sizelineinfo = n; 185 | LoadVector(S, f->lineinfo, n); 186 | n = LoadInt(S); 187 | f->locvars = luaM_newvector(S->L, n, LocVar); 188 | f->sizelocvars = n; 189 | for (i = 0; i < n; i++) 190 | f->locvars[i].varname = NULL; 191 | for (i = 0; i < n; i++) { 192 | f->locvars[i].varname = LoadString(S); 193 | f->locvars[i].startpc = LoadInt(S); 194 | f->locvars[i].endpc = LoadInt(S); 195 | } 196 | n = LoadInt(S); 197 | for (i = 0; i < n; i++) 198 | f->upvalues[i].name = LoadString(S); 199 | } 200 | 201 | 202 | static void LoadFunction (LoadState *S, Proto *f, TString *psource) { 203 | f->source = LoadString(S); 204 | if (f->source == NULL) /* no source in dump? */ 205 | f->source = psource; /* reuse parent's source */ 206 | f->linedefined = LoadInt(S); 207 | f->lastlinedefined = LoadInt(S); 208 | f->numparams = LoadByte(S); 209 | f->is_vararg = LoadByte(S); 210 | f->maxstacksize = LoadByte(S); 211 | LoadCode(S, f); 212 | LoadConstants(S, f); 213 | LoadUpvalues(S, f); 214 | LoadProtos(S, f); 215 | LoadDebug(S, f); 216 | } 217 | 218 | 219 | static void checkliteral (LoadState *S, const char *s, const char *msg) { 220 | char buff[sizeof(LUA_SIGNATURE) + sizeof(LUAC_DATA)]; /* larger than both */ 221 | size_t len = strlen(s); 222 | LoadVector(S, buff, len); 223 | if (memcmp(s, buff, len) != 0) 224 | error(S, msg); 225 | } 226 | 227 | 228 | static void fchecksize (LoadState *S, size_t size, const char *tname) { 229 | if (LoadByte(S) != size) 230 | error(S, luaO_pushfstring(S->L, "%s size mismatch in", tname)); 231 | } 232 | 233 | 234 | #define checksize(S,t) fchecksize(S,sizeof(t),#t) 235 | 236 | static void checkHeader (LoadState *S) { 237 | checkliteral(S, LUA_SIGNATURE + 1, "not a"); /* 1st char already checked */ 238 | if (LoadByte(S) != LUAC_VERSION) 239 | error(S, "version mismatch in"); 240 | if (LoadByte(S) != LUAC_FORMAT) 241 | error(S, "format mismatch in"); 242 | checkliteral(S, LUAC_DATA, "corrupted"); 243 | checksize(S, int); 244 | checksize(S, size_t); 245 | checksize(S, Instruction); 246 | checksize(S, lua_Integer); 247 | checksize(S, lua_Number); 248 | if (LoadInteger(S) != LUAC_INT) 249 | error(S, "endianness mismatch in"); 250 | if (LoadNumber(S) != LUAC_NUM) 251 | error(S, "float format mismatch in"); 252 | } 253 | 254 | 255 | /* 256 | ** load precompiled chunk 257 | */ 258 | LClosure *luaU_undump(lua_State *L, ZIO *Z, const char *name) { 259 | LoadState S; 260 | LClosure *cl; 261 | if (*name == '@' || *name == '=') 262 | S.name = name + 1; 263 | else if (*name == LUA_SIGNATURE[0]) 264 | S.name = "binary string"; 265 | else 266 | S.name = name; 267 | S.L = L; 268 | S.Z = Z; 269 | checkHeader(&S); 270 | cl = luaF_newLclosure(L, LoadByte(&S)); 271 | setclLvalue(L, L->top, cl); 272 | luaD_inctop(L); 273 | cl->p = luaF_newproto(L); 274 | LoadFunction(&S, cl->p, NULL); 275 | lua_assert(cl->nupvalues == cl->p->sizeupvalues); 276 | luai_verifycode(L, buff, cl->p); 277 | return cl; 278 | } 279 | 280 | -------------------------------------------------------------------------------- /src/lua-5.3.5/src/lundump.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lundump.h,v 1.45.1.1 2017/04/19 17:20:42 roberto Exp $ 3 | ** load precompiled Lua chunks 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef lundump_h 8 | #define lundump_h 9 | 10 | #include "llimits.h" 11 | #include "lobject.h" 12 | #include "lzio.h" 13 | 14 | 15 | /* data to catch conversion errors */ 16 | #define LUAC_DATA "\x19\x93\r\n\x1a\n" 17 | 18 | #define LUAC_INT 0x5678 19 | #define LUAC_NUM cast_num(370.5) 20 | 21 | #define MYINT(s) (s[0]-'0') 22 | #define LUAC_VERSION (MYINT(LUA_VERSION_MAJOR)*16+MYINT(LUA_VERSION_MINOR)) 23 | #define LUAC_FORMAT 0 /* this is the official format */ 24 | 25 | /* load one chunk; from lundump.c */ 26 | LUAI_FUNC LClosure* luaU_undump (lua_State* L, ZIO* Z, const char* name); 27 | 28 | /* dump one chunk; from ldump.c */ 29 | LUAI_FUNC int luaU_dump (lua_State* L, const Proto* f, lua_Writer w, 30 | void* data, int strip); 31 | 32 | #endif 33 | -------------------------------------------------------------------------------- /src/lua-5.3.5/src/lvm.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lvm.h,v 2.41.1.1 2017/04/19 17:20:42 roberto Exp $ 3 | ** Lua virtual machine 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef lvm_h 8 | #define lvm_h 9 | 10 | 11 | #include "ldo.h" 12 | #include "lobject.h" 13 | #include "ltm.h" 14 | 15 | 16 | #if !defined(LUA_NOCVTN2S) 17 | #define cvt2str(o) ttisnumber(o) 18 | #else 19 | #define cvt2str(o) 0 /* no conversion from numbers to strings */ 20 | #endif 21 | 22 | 23 | #if !defined(LUA_NOCVTS2N) 24 | #define cvt2num(o) ttisstring(o) 25 | #else 26 | #define cvt2num(o) 0 /* no conversion from strings to numbers */ 27 | #endif 28 | 29 | 30 | /* 31 | ** You can define LUA_FLOORN2I if you want to convert floats to integers 32 | ** by flooring them (instead of raising an error if they are not 33 | ** integral values) 34 | */ 35 | #if !defined(LUA_FLOORN2I) 36 | #define LUA_FLOORN2I 0 37 | #endif 38 | 39 | 40 | #define tonumber(o,n) \ 41 | (ttisfloat(o) ? (*(n) = fltvalue(o), 1) : luaV_tonumber_(o,n)) 42 | 43 | #define tointeger(o,i) \ 44 | (ttisinteger(o) ? (*(i) = ivalue(o), 1) : luaV_tointeger(o,i,LUA_FLOORN2I)) 45 | 46 | #define intop(op,v1,v2) l_castU2S(l_castS2U(v1) op l_castS2U(v2)) 47 | 48 | #define luaV_rawequalobj(t1,t2) luaV_equalobj(NULL,t1,t2) 49 | 50 | 51 | /* 52 | ** fast track for 'gettable': if 't' is a table and 't[k]' is not nil, 53 | ** return 1 with 'slot' pointing to 't[k]' (final result). Otherwise, 54 | ** return 0 (meaning it will have to check metamethod) with 'slot' 55 | ** pointing to a nil 't[k]' (if 't' is a table) or NULL (otherwise). 56 | ** 'f' is the raw get function to use. 57 | */ 58 | #define luaV_fastget(L,t,k,slot,f) \ 59 | (!ttistable(t) \ 60 | ? (slot = NULL, 0) /* not a table; 'slot' is NULL and result is 0 */ \ 61 | : (slot = f(hvalue(t), k), /* else, do raw access */ \ 62 | !ttisnil(slot))) /* result not nil? */ 63 | 64 | /* 65 | ** standard implementation for 'gettable' 66 | */ 67 | #define luaV_gettable(L,t,k,v) { const TValue *slot; \ 68 | if (luaV_fastget(L,t,k,slot,luaH_get)) { setobj2s(L, v, slot); } \ 69 | else luaV_finishget(L,t,k,v,slot); } 70 | 71 | 72 | /* 73 | ** Fast track for set table. If 't' is a table and 't[k]' is not nil, 74 | ** call GC barrier, do a raw 't[k]=v', and return true; otherwise, 75 | ** return false with 'slot' equal to NULL (if 't' is not a table) or 76 | ** 'nil'. (This is needed by 'luaV_finishget'.) Note that, if the macro 77 | ** returns true, there is no need to 'invalidateTMcache', because the 78 | ** call is not creating a new entry. 79 | */ 80 | #define luaV_fastset(L,t,k,slot,f,v) \ 81 | (!ttistable(t) \ 82 | ? (slot = NULL, 0) \ 83 | : (slot = f(hvalue(t), k), \ 84 | ttisnil(slot) ? 0 \ 85 | : (luaC_barrierback(L, hvalue(t), v), \ 86 | setobj2t(L, cast(TValue *,slot), v), \ 87 | 1))) 88 | 89 | 90 | #define luaV_settable(L,t,k,v) { const TValue *slot; \ 91 | if (!luaV_fastset(L,t,k,slot,luaH_get,v)) \ 92 | luaV_finishset(L,t,k,v,slot); } 93 | 94 | 95 | 96 | LUAI_FUNC int luaV_equalobj (lua_State *L, const TValue *t1, const TValue *t2); 97 | LUAI_FUNC int luaV_lessthan (lua_State *L, const TValue *l, const TValue *r); 98 | LUAI_FUNC int luaV_lessequal (lua_State *L, const TValue *l, const TValue *r); 99 | LUAI_FUNC int luaV_tonumber_ (const TValue *obj, lua_Number *n); 100 | LUAI_FUNC int luaV_tointeger (const TValue *obj, lua_Integer *p, int mode); 101 | LUAI_FUNC void luaV_finishget (lua_State *L, const TValue *t, TValue *key, 102 | StkId val, const TValue *slot); 103 | LUAI_FUNC void luaV_finishset (lua_State *L, const TValue *t, TValue *key, 104 | StkId val, const TValue *slot); 105 | LUAI_FUNC void luaV_finishOp (lua_State *L); 106 | LUAI_FUNC void luaV_execute (lua_State *L); 107 | LUAI_FUNC void luaV_concat (lua_State *L, int total); 108 | LUAI_FUNC lua_Integer luaV_div (lua_State *L, lua_Integer x, lua_Integer y); 109 | LUAI_FUNC lua_Integer luaV_mod (lua_State *L, lua_Integer x, lua_Integer y); 110 | LUAI_FUNC lua_Integer luaV_shiftl (lua_Integer x, lua_Integer y); 111 | LUAI_FUNC void luaV_objlen (lua_State *L, StkId ra, const TValue *rb); 112 | 113 | #endif 114 | -------------------------------------------------------------------------------- /src/lua-5.3.5/src/lzio.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lzio.c,v 1.37.1.1 2017/04/19 17:20:42 roberto Exp $ 3 | ** Buffered streams 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #define lzio_c 8 | #define LUA_CORE 9 | 10 | #include "lprefix.h" 11 | 12 | 13 | #include 14 | 15 | #include "lua.h" 16 | 17 | #include "llimits.h" 18 | #include "lmem.h" 19 | #include "lstate.h" 20 | #include "lzio.h" 21 | 22 | 23 | int luaZ_fill (ZIO *z) { 24 | size_t size; 25 | lua_State *L = z->L; 26 | const char *buff; 27 | lua_unlock(L); 28 | buff = z->reader(L, z->data, &size); 29 | lua_lock(L); 30 | if (buff == NULL || size == 0) 31 | return EOZ; 32 | z->n = size - 1; /* discount char being returned */ 33 | z->p = buff; 34 | return cast_uchar(*(z->p++)); 35 | } 36 | 37 | 38 | void luaZ_init (lua_State *L, ZIO *z, lua_Reader reader, void *data) { 39 | z->L = L; 40 | z->reader = reader; 41 | z->data = data; 42 | z->n = 0; 43 | z->p = NULL; 44 | } 45 | 46 | 47 | /* --------------------------------------------------------------- read --- */ 48 | size_t luaZ_read (ZIO *z, void *b, size_t n) { 49 | while (n) { 50 | size_t m; 51 | if (z->n == 0) { /* no bytes in buffer? */ 52 | if (luaZ_fill(z) == EOZ) /* try to read more */ 53 | return n; /* no more input; return number of missing bytes */ 54 | else { 55 | z->n++; /* luaZ_fill consumed first byte; put it back */ 56 | z->p--; 57 | } 58 | } 59 | m = (n <= z->n) ? n : z->n; /* min. between n and z->n */ 60 | memcpy(b, z->p, m); 61 | z->n -= m; 62 | z->p += m; 63 | b = (char *)b + m; 64 | n -= m; 65 | } 66 | return 0; 67 | } 68 | 69 | -------------------------------------------------------------------------------- /src/lua-5.3.5/src/lzio.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lzio.h,v 1.31.1.1 2017/04/19 17:20:42 roberto Exp $ 3 | ** Buffered streams 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | 8 | #ifndef lzio_h 9 | #define lzio_h 10 | 11 | #include "lua.h" 12 | 13 | #include "lmem.h" 14 | 15 | 16 | #define EOZ (-1) /* end of stream */ 17 | 18 | typedef struct Zio ZIO; 19 | 20 | #define zgetc(z) (((z)->n--)>0 ? cast_uchar(*(z)->p++) : luaZ_fill(z)) 21 | 22 | 23 | typedef struct Mbuffer { 24 | char *buffer; 25 | size_t n; 26 | size_t buffsize; 27 | } Mbuffer; 28 | 29 | #define luaZ_initbuffer(L, buff) ((buff)->buffer = NULL, (buff)->buffsize = 0) 30 | 31 | #define luaZ_buffer(buff) ((buff)->buffer) 32 | #define luaZ_sizebuffer(buff) ((buff)->buffsize) 33 | #define luaZ_bufflen(buff) ((buff)->n) 34 | 35 | #define luaZ_buffremove(buff,i) ((buff)->n -= (i)) 36 | #define luaZ_resetbuffer(buff) ((buff)->n = 0) 37 | 38 | 39 | #define luaZ_resizebuffer(L, buff, size) \ 40 | ((buff)->buffer = luaM_reallocvchar(L, (buff)->buffer, \ 41 | (buff)->buffsize, size), \ 42 | (buff)->buffsize = size) 43 | 44 | #define luaZ_freebuffer(L, buff) luaZ_resizebuffer(L, buff, 0) 45 | 46 | 47 | LUAI_FUNC void luaZ_init (lua_State *L, ZIO *z, lua_Reader reader, 48 | void *data); 49 | LUAI_FUNC size_t luaZ_read (ZIO* z, void *b, size_t n); /* read next n bytes */ 50 | 51 | 52 | 53 | /* --------- Private Part ------------------ */ 54 | 55 | struct Zio { 56 | size_t n; /* bytes still unread */ 57 | const char *p; /* current position in buffer */ 58 | lua_Reader reader; /* reader function */ 59 | void *data; /* additional data */ 60 | lua_State *L; /* Lua state (for reader) */ 61 | }; 62 | 63 | 64 | LUAI_FUNC int luaZ_fill (ZIO *z); 65 | 66 | #endif 67 | -------------------------------------------------------------------------------- /src/speex/arch.h: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2003 Jean-Marc Valin */ 2 | /** 3 | @file arch.h 4 | @brief Various architecture definitions Speex 5 | */ 6 | /* 7 | Redistribution and use in source and binary forms, with or without 8 | modification, are permitted provided that the following conditions 9 | are met: 10 | 11 | - Redistributions of source code must retain the above copyright 12 | notice, this list of conditions and the following disclaimer. 13 | 14 | - Redistributions in binary form must reproduce the above copyright 15 | notice, this list of conditions and the following disclaimer in the 16 | documentation and/or other materials provided with the distribution. 17 | 18 | - Neither the name of the Xiph.org Foundation nor the names of its 19 | contributors may be used to endorse or promote products derived from 20 | this software without specific prior written permission. 21 | 22 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 23 | ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 24 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 25 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR 26 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 27 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 28 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 29 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 30 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 31 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 32 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 | */ 34 | 35 | #ifndef ARCH_H 36 | #define ARCH_H 37 | 38 | /* A couple test to catch stupid option combinations */ 39 | #ifdef FIXED_POINT 40 | 41 | #ifdef FLOATING_POINT 42 | #error You cannot compile as floating point and fixed point at the same time 43 | #endif 44 | #ifdef _USE_SSE 45 | #error SSE is only for floating-point 46 | #endif 47 | #if ((defined (ARM4_ASM)||defined (ARM4_ASM)) && defined(BFIN_ASM)) || (defined (ARM4_ASM)&&defined(ARM5E_ASM)) 48 | #error Make up your mind. What CPU do you have? 49 | #endif 50 | #ifdef VORBIS_PSYCHO 51 | #error Vorbis-psy model currently not implemented in fixed-point 52 | #endif 53 | 54 | #else 55 | 56 | #ifndef FLOATING_POINT 57 | #error You now need to define either FIXED_POINT or FLOATING_POINT 58 | #endif 59 | #if defined (ARM4_ASM) || defined(ARM5E_ASM) || defined(BFIN_ASM) 60 | #error I suppose you can have a [ARM4/ARM5E/Blackfin] that has float instructions? 61 | #endif 62 | #ifdef FIXED_POINT_DEBUG 63 | #error "Don't you think enabling fixed-point is a good thing to do if you want to debug that?" 64 | #endif 65 | 66 | 67 | #endif 68 | 69 | #ifndef OUTSIDE_SPEEX 70 | #include "speex/speexdsp_types.h" 71 | #endif 72 | 73 | #define ABS(x) ((x) < 0 ? (-(x)) : (x)) /**< Absolute integer value. */ 74 | #define ABS16(x) ((x) < 0 ? (-(x)) : (x)) /**< Absolute 16-bit value. */ 75 | #define MIN16(a,b) ((a) < (b) ? (a) : (b)) /**< Maximum 16-bit value. */ 76 | #define MAX16(a,b) ((a) > (b) ? (a) : (b)) /**< Maximum 16-bit value. */ 77 | #define ABS32(x) ((x) < 0 ? (-(x)) : (x)) /**< Absolute 32-bit value. */ 78 | #define MIN32(a,b) ((a) < (b) ? (a) : (b)) /**< Maximum 32-bit value. */ 79 | #define MAX32(a,b) ((a) > (b) ? (a) : (b)) /**< Maximum 32-bit value. */ 80 | 81 | #ifdef FIXED_POINT 82 | 83 | typedef spx_int16_t spx_word16_t; 84 | typedef spx_int32_t spx_word32_t; 85 | typedef spx_word32_t spx_mem_t; 86 | typedef spx_word16_t spx_coef_t; 87 | typedef spx_word16_t spx_lsp_t; 88 | typedef spx_word32_t spx_sig_t; 89 | 90 | #define Q15ONE 32767 91 | 92 | #define LPC_SCALING 8192 93 | #define SIG_SCALING 16384 94 | #define LSP_SCALING 8192. 95 | #define GAMMA_SCALING 32768. 96 | #define GAIN_SCALING 64 97 | #define GAIN_SCALING_1 0.015625 98 | 99 | #define LPC_SHIFT 13 100 | #define LSP_SHIFT 13 101 | #define SIG_SHIFT 14 102 | #define GAIN_SHIFT 6 103 | 104 | #define VERY_SMALL 0 105 | #define VERY_LARGE32 ((spx_word32_t)2147483647) 106 | #define VERY_LARGE16 ((spx_word16_t)32767) 107 | #define Q15_ONE ((spx_word16_t)32767) 108 | 109 | 110 | #ifdef FIXED_DEBUG 111 | #include "fixed_debug.h" 112 | #else 113 | 114 | #include "fixed_generic.h" 115 | 116 | #ifdef ARM5E_ASM 117 | #include "fixed_arm5e.h" 118 | #elif defined (ARM4_ASM) 119 | #include "fixed_arm4.h" 120 | #elif defined (BFIN_ASM) 121 | #include "fixed_bfin.h" 122 | #endif 123 | 124 | #endif 125 | 126 | 127 | #else 128 | 129 | typedef float spx_mem_t; 130 | typedef float spx_coef_t; 131 | typedef float spx_lsp_t; 132 | typedef float spx_sig_t; 133 | typedef float spx_word16_t; 134 | typedef float spx_word32_t; 135 | 136 | #define Q15ONE 1.0f 137 | #define LPC_SCALING 1.f 138 | #define SIG_SCALING 1.f 139 | #define LSP_SCALING 1.f 140 | #define GAMMA_SCALING 1.f 141 | #define GAIN_SCALING 1.f 142 | #define GAIN_SCALING_1 1.f 143 | 144 | 145 | #define VERY_SMALL 1e-15f 146 | #define VERY_LARGE32 1e15f 147 | #define VERY_LARGE16 1e15f 148 | #define Q15_ONE ((spx_word16_t)1.f) 149 | 150 | #define QCONST16(x,bits) (x) 151 | #define QCONST32(x,bits) (x) 152 | 153 | #define NEG16(x) (-(x)) 154 | #define NEG32(x) (-(x)) 155 | #define EXTRACT16(x) (x) 156 | #define EXTEND32(x) (x) 157 | #define SHR16(a,shift) (a) 158 | #define SHL16(a,shift) (a) 159 | #define SHR32(a,shift) (a) 160 | #define SHL32(a,shift) (a) 161 | #define PSHR16(a,shift) (a) 162 | #define PSHR32(a,shift) (a) 163 | #define VSHR32(a,shift) (a) 164 | #define SATURATE16(x,a) (x) 165 | #define SATURATE32(x,a) (x) 166 | #define SATURATE32PSHR(x,shift,a) (x) 167 | 168 | #define PSHR(a,shift) (a) 169 | #define SHR(a,shift) (a) 170 | #define SHL(a,shift) (a) 171 | #define SATURATE(x,a) (x) 172 | 173 | #define ADD16(a,b) ((a)+(b)) 174 | #define SUB16(a,b) ((a)-(b)) 175 | #define ADD32(a,b) ((a)+(b)) 176 | #define SUB32(a,b) ((a)-(b)) 177 | #define MULT16_16_16(a,b) ((a)*(b)) 178 | #define MULT16_16(a,b) ((spx_word32_t)(a)*(spx_word32_t)(b)) 179 | #define MAC16_16(c,a,b) ((c)+(spx_word32_t)(a)*(spx_word32_t)(b)) 180 | 181 | #define MULT16_32_Q11(a,b) ((a)*(b)) 182 | #define MULT16_32_Q13(a,b) ((a)*(b)) 183 | #define MULT16_32_Q14(a,b) ((a)*(b)) 184 | #define MULT16_32_Q15(a,b) ((a)*(b)) 185 | #define MULT16_32_P15(a,b) ((a)*(b)) 186 | 187 | #define MAC16_32_Q11(c,a,b) ((c)+(a)*(b)) 188 | #define MAC16_32_Q15(c,a,b) ((c)+(a)*(b)) 189 | 190 | #define MAC16_16_Q11(c,a,b) ((c)+(a)*(b)) 191 | #define MAC16_16_Q13(c,a,b) ((c)+(a)*(b)) 192 | #define MAC16_16_P13(c,a,b) ((c)+(a)*(b)) 193 | #define MULT16_16_Q11_32(a,b) ((a)*(b)) 194 | #define MULT16_16_Q13(a,b) ((a)*(b)) 195 | #define MULT16_16_Q14(a,b) ((a)*(b)) 196 | #define MULT16_16_Q15(a,b) ((a)*(b)) 197 | #define MULT16_16_P15(a,b) ((a)*(b)) 198 | #define MULT16_16_P13(a,b) ((a)*(b)) 199 | #define MULT16_16_P14(a,b) ((a)*(b)) 200 | 201 | #define DIV32_16(a,b) (((spx_word32_t)(a))/(spx_word16_t)(b)) 202 | #define PDIV32_16(a,b) (((spx_word32_t)(a))/(spx_word16_t)(b)) 203 | #define DIV32(a,b) (((spx_word32_t)(a))/(spx_word32_t)(b)) 204 | #define PDIV32(a,b) (((spx_word32_t)(a))/(spx_word32_t)(b)) 205 | 206 | 207 | #endif 208 | 209 | 210 | #if defined (CONFIG_TI_C54X) || defined (CONFIG_TI_C55X) 211 | 212 | /* 2 on TI C5x DSP */ 213 | #define BYTES_PER_CHAR 2 214 | #define BITS_PER_CHAR 16 215 | #define LOG2_BITS_PER_CHAR 4 216 | 217 | #else 218 | 219 | #define BYTES_PER_CHAR 1 220 | #define BITS_PER_CHAR 8 221 | #define LOG2_BITS_PER_CHAR 3 222 | 223 | #endif 224 | 225 | 226 | 227 | #ifdef FIXED_DEBUG 228 | extern long long spx_mips; 229 | #endif 230 | 231 | 232 | #endif 233 | -------------------------------------------------------------------------------- /src/speex/fixed_arm4.h: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2004 Jean-Marc Valin */ 2 | /** 3 | @file fixed_arm4.h 4 | @brief ARM4 fixed-point operations 5 | */ 6 | /* 7 | Redistribution and use in source and binary forms, with or without 8 | modification, are permitted provided that the following conditions 9 | are met: 10 | 11 | - Redistributions of source code must retain the above copyright 12 | notice, this list of conditions and the following disclaimer. 13 | 14 | - Redistributions in binary form must reproduce the above copyright 15 | notice, this list of conditions and the following disclaimer in the 16 | documentation and/or other materials provided with the distribution. 17 | 18 | - Neither the name of the Xiph.org Foundation nor the names of its 19 | contributors may be used to endorse or promote products derived from 20 | this software without specific prior written permission. 21 | 22 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 23 | ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 24 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 25 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR 26 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 27 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 28 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 29 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 30 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 31 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 32 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 | */ 34 | 35 | #ifndef FIXED_ARM4_H 36 | #define FIXED_ARM4_H 37 | 38 | #undef MULT16_32_Q14 39 | static inline spx_word32_t MULT16_32_Q14(spx_word16_t x, spx_word32_t y) { 40 | int res; 41 | int dummy; 42 | asm ( 43 | "smull %0,%1,%2,%3 \n\t" 44 | "mov %0, %0, lsr #14 \n\t" 45 | "add %0, %0, %1, lsl #18 \n\t" 46 | : "=&r"(res), "=&r" (dummy) 47 | : "r"(y),"r"((int)x)); 48 | return(res); 49 | } 50 | 51 | #undef MULT16_32_Q15 52 | static inline spx_word32_t MULT16_32_Q15(spx_word16_t x, spx_word32_t y) { 53 | int res; 54 | int dummy; 55 | asm ( 56 | "smull %0,%1,%2,%3 \n\t" 57 | "mov %0, %0, lsr #15 \n\t" 58 | "add %0, %0, %1, lsl #17 \n\t" 59 | : "=&r"(res), "=&r" (dummy) 60 | : "r"(y),"r"((int)x)); 61 | return(res); 62 | } 63 | 64 | #undef DIV32_16 65 | static inline short DIV32_16(int a, int b) 66 | { 67 | int res=0; 68 | int dead1, dead2, dead3, dead4, dead5; 69 | __asm__ __volatile__ ( 70 | "\teor %5, %0, %1\n" 71 | "\tmovs %4, %0\n" 72 | "\trsbmi %0, %0, #0 \n" 73 | "\tmovs %4, %1\n" 74 | "\trsbmi %1, %1, #0 \n" 75 | "\tmov %4, #1\n" 76 | 77 | "\tsubs %3, %0, %1, asl #14 \n" 78 | "\tmovpl %0, %3 \n" 79 | "\torrpl %2, %2, %4, asl #14 \n" 80 | 81 | "\tsubs %3, %0, %1, asl #13 \n" 82 | "\tmovpl %0, %3 \n" 83 | "\torrpl %2, %2, %4, asl #13 \n" 84 | 85 | "\tsubs %3, %0, %1, asl #12 \n" 86 | "\tmovpl %0, %3 \n" 87 | "\torrpl %2, %2, %4, asl #12 \n" 88 | 89 | "\tsubs %3, %0, %1, asl #11 \n" 90 | "\tmovpl %0, %3 \n" 91 | "\torrpl %2, %2, %4, asl #11 \n" 92 | 93 | "\tsubs %3, %0, %1, asl #10 \n" 94 | "\tmovpl %0, %3 \n" 95 | "\torrpl %2, %2, %4, asl #10 \n" 96 | 97 | "\tsubs %3, %0, %1, asl #9 \n" 98 | "\tmovpl %0, %3 \n" 99 | "\torrpl %2, %2, %4, asl #9 \n" 100 | 101 | "\tsubs %3, %0, %1, asl #8 \n" 102 | "\tmovpl %0, %3 \n" 103 | "\torrpl %2, %2, %4, asl #8 \n" 104 | 105 | "\tsubs %3, %0, %1, asl #7 \n" 106 | "\tmovpl %0, %3 \n" 107 | "\torrpl %2, %2, %4, asl #7 \n" 108 | 109 | "\tsubs %3, %0, %1, asl #6 \n" 110 | "\tmovpl %0, %3 \n" 111 | "\torrpl %2, %2, %4, asl #6 \n" 112 | 113 | "\tsubs %3, %0, %1, asl #5 \n" 114 | "\tmovpl %0, %3 \n" 115 | "\torrpl %2, %2, %4, asl #5 \n" 116 | 117 | "\tsubs %3, %0, %1, asl #4 \n" 118 | "\tmovpl %0, %3 \n" 119 | "\torrpl %2, %2, %4, asl #4 \n" 120 | 121 | "\tsubs %3, %0, %1, asl #3 \n" 122 | "\tmovpl %0, %3 \n" 123 | "\torrpl %2, %2, %4, asl #3 \n" 124 | 125 | "\tsubs %3, %0, %1, asl #2 \n" 126 | "\tmovpl %0, %3 \n" 127 | "\torrpl %2, %2, %4, asl #2 \n" 128 | 129 | "\tsubs %3, %0, %1, asl #1 \n" 130 | "\tmovpl %0, %3 \n" 131 | "\torrpl %2, %2, %4, asl #1 \n" 132 | 133 | "\tsubs %3, %0, %1 \n" 134 | "\tmovpl %0, %3 \n" 135 | "\torrpl %2, %2, %4 \n" 136 | 137 | "\tmovs %5, %5, lsr #31 \n" 138 | "\trsbne %2, %2, #0 \n" 139 | : "=r" (dead1), "=r" (dead2), "=r" (res), 140 | "=r" (dead3), "=r" (dead4), "=r" (dead5) 141 | : "0" (a), "1" (b), "2" (res) 142 | : "cc" 143 | ); 144 | return res; 145 | } 146 | 147 | 148 | #endif 149 | -------------------------------------------------------------------------------- /src/speex/fixed_arm5e.h: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2003 Jean-Marc Valin */ 2 | /** 3 | @file fixed_arm5e.h 4 | @brief ARM-tuned fixed-point operations 5 | */ 6 | /* 7 | Redistribution and use in source and binary forms, with or without 8 | modification, are permitted provided that the following conditions 9 | are met: 10 | 11 | - Redistributions of source code must retain the above copyright 12 | notice, this list of conditions and the following disclaimer. 13 | 14 | - Redistributions in binary form must reproduce the above copyright 15 | notice, this list of conditions and the following disclaimer in the 16 | documentation and/or other materials provided with the distribution. 17 | 18 | - Neither the name of the Xiph.org Foundation nor the names of its 19 | contributors may be used to endorse or promote products derived from 20 | this software without specific prior written permission. 21 | 22 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 23 | ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 24 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 25 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR 26 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 27 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 28 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 29 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 30 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 31 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 32 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 | */ 34 | 35 | #ifndef FIXED_ARM5E_H 36 | #define FIXED_ARM5E_H 37 | 38 | #undef MULT16_16 39 | static inline spx_word32_t MULT16_16(spx_word16_t x, spx_word16_t y) { 40 | int res; 41 | asm ("smulbb %0,%1,%2;\n" 42 | : "=&r"(res) 43 | : "%r"(x),"r"(y)); 44 | return(res); 45 | } 46 | 47 | #undef MAC16_16 48 | static inline spx_word32_t MAC16_16(spx_word32_t a, spx_word16_t x, spx_word32_t y) { 49 | int res; 50 | asm ("smlabb %0,%1,%2,%3;\n" 51 | : "=&r"(res) 52 | : "%r"(x),"r"(y),"r"(a)); 53 | return(res); 54 | } 55 | 56 | #undef MULT16_32_Q15 57 | static inline spx_word32_t MULT16_32_Q15(spx_word16_t x, spx_word32_t y) { 58 | int res; 59 | asm ("smulwb %0,%1,%2;\n" 60 | : "=&r"(res) 61 | : "%r"(y<<1),"r"(x)); 62 | return(res); 63 | } 64 | 65 | #undef MAC16_32_Q15 66 | static inline spx_word32_t MAC16_32_Q15(spx_word32_t a, spx_word16_t x, spx_word32_t y) { 67 | int res; 68 | asm ("smlawb %0,%1,%2,%3;\n" 69 | : "=&r"(res) 70 | : "%r"(y<<1),"r"(x),"r"(a)); 71 | return(res); 72 | } 73 | 74 | #undef MULT16_32_Q11 75 | static inline spx_word32_t MULT16_32_Q11(spx_word16_t x, spx_word32_t y) { 76 | int res; 77 | asm ("smulwb %0,%1,%2;\n" 78 | : "=&r"(res) 79 | : "%r"(y<<5),"r"(x)); 80 | return(res); 81 | } 82 | 83 | #undef MAC16_32_Q11 84 | static inline spx_word32_t MAC16_32_Q11(spx_word32_t a, spx_word16_t x, spx_word32_t y) { 85 | int res; 86 | asm ("smlawb %0,%1,%2,%3;\n" 87 | : "=&r"(res) 88 | : "%r"(y<<5),"r"(x),"r"(a)); 89 | return(res); 90 | } 91 | 92 | #undef DIV32_16 93 | static inline short DIV32_16(int a, int b) 94 | { 95 | int res=0; 96 | int dead1, dead2, dead3, dead4, dead5; 97 | __asm__ __volatile__ ( 98 | "\teor %5, %0, %1\n" 99 | "\tmovs %4, %0\n" 100 | "\trsbmi %0, %0, #0 \n" 101 | "\tmovs %4, %1\n" 102 | "\trsbmi %1, %1, #0 \n" 103 | "\tmov %4, #1\n" 104 | 105 | "\tsubs %3, %0, %1, asl #14 \n" 106 | "\torrpl %2, %2, %4, asl #14 \n" 107 | "\tmovpl %0, %3 \n" 108 | 109 | "\tsubs %3, %0, %1, asl #13 \n" 110 | "\torrpl %2, %2, %4, asl #13 \n" 111 | "\tmovpl %0, %3 \n" 112 | 113 | "\tsubs %3, %0, %1, asl #12 \n" 114 | "\torrpl %2, %2, %4, asl #12 \n" 115 | "\tmovpl %0, %3 \n" 116 | 117 | "\tsubs %3, %0, %1, asl #11 \n" 118 | "\torrpl %2, %2, %4, asl #11 \n" 119 | "\tmovpl %0, %3 \n" 120 | 121 | "\tsubs %3, %0, %1, asl #10 \n" 122 | "\torrpl %2, %2, %4, asl #10 \n" 123 | "\tmovpl %0, %3 \n" 124 | 125 | "\tsubs %3, %0, %1, asl #9 \n" 126 | "\torrpl %2, %2, %4, asl #9 \n" 127 | "\tmovpl %0, %3 \n" 128 | 129 | "\tsubs %3, %0, %1, asl #8 \n" 130 | "\torrpl %2, %2, %4, asl #8 \n" 131 | "\tmovpl %0, %3 \n" 132 | 133 | "\tsubs %3, %0, %1, asl #7 \n" 134 | "\torrpl %2, %2, %4, asl #7 \n" 135 | "\tmovpl %0, %3 \n" 136 | 137 | "\tsubs %3, %0, %1, asl #6 \n" 138 | "\torrpl %2, %2, %4, asl #6 \n" 139 | "\tmovpl %0, %3 \n" 140 | 141 | "\tsubs %3, %0, %1, asl #5 \n" 142 | "\torrpl %2, %2, %4, asl #5 \n" 143 | "\tmovpl %0, %3 \n" 144 | 145 | "\tsubs %3, %0, %1, asl #4 \n" 146 | "\torrpl %2, %2, %4, asl #4 \n" 147 | "\tmovpl %0, %3 \n" 148 | 149 | "\tsubs %3, %0, %1, asl #3 \n" 150 | "\torrpl %2, %2, %4, asl #3 \n" 151 | "\tmovpl %0, %3 \n" 152 | 153 | "\tsubs %3, %0, %1, asl #2 \n" 154 | "\torrpl %2, %2, %4, asl #2 \n" 155 | "\tmovpl %0, %3 \n" 156 | 157 | "\tsubs %3, %0, %1, asl #1 \n" 158 | "\torrpl %2, %2, %4, asl #1 \n" 159 | "\tmovpl %0, %3 \n" 160 | 161 | "\tsubs %3, %0, %1 \n" 162 | "\torrpl %2, %2, %4 \n" 163 | "\tmovpl %0, %3 \n" 164 | 165 | "\tmovs %5, %5, lsr #31 \n" 166 | "\trsbne %2, %2, #0 \n" 167 | : "=r" (dead1), "=r" (dead2), "=r" (res), 168 | "=r" (dead3), "=r" (dead4), "=r" (dead5) 169 | : "0" (a), "1" (b), "2" (res) 170 | : "memory", "cc" 171 | ); 172 | return res; 173 | } 174 | 175 | 176 | 177 | 178 | #endif 179 | -------------------------------------------------------------------------------- /src/speex/fixed_bfin.h: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2005 Analog Devices 2 | Author: Jean-Marc Valin */ 3 | /** 4 | @file fixed_bfin.h 5 | @brief Blackfin fixed-point operations 6 | */ 7 | /* 8 | Redistribution and use in source and binary forms, with or without 9 | modification, are permitted provided that the following conditions 10 | are met: 11 | 12 | - Redistributions of source code must retain the above copyright 13 | notice, this list of conditions and the following disclaimer. 14 | 15 | - Redistributions in binary form must reproduce the above copyright 16 | notice, this list of conditions and the following disclaimer in the 17 | documentation and/or other materials provided with the distribution. 18 | 19 | - Neither the name of the Xiph.org Foundation nor the names of its 20 | contributors may be used to endorse or promote products derived from 21 | this software without specific prior written permission. 22 | 23 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 24 | ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 25 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 26 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR 27 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 28 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 29 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 30 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 31 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 32 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 33 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | */ 35 | 36 | #ifndef FIXED_BFIN_H 37 | #define FIXED_BFIN_H 38 | 39 | #include "bfin.h" 40 | 41 | #undef PDIV32_16 42 | static inline spx_word16_t PDIV32_16(spx_word32_t a, spx_word16_t b) 43 | { 44 | spx_word32_t res, bb; 45 | bb = b; 46 | a += b>>1; 47 | __asm__ ( 48 | "P0 = 15;\n\t" 49 | "R0 = %1;\n\t" 50 | "R1 = %2;\n\t" 51 | //"R0 = R0 + R1;\n\t" 52 | "R0 <<= 1;\n\t" 53 | "DIVS (R0, R1);\n\t" 54 | "LOOP divide%= LC0 = P0;\n\t" 55 | "LOOP_BEGIN divide%=;\n\t" 56 | "DIVQ (R0, R1);\n\t" 57 | "LOOP_END divide%=;\n\t" 58 | "R0 = R0.L;\n\t" 59 | "%0 = R0;\n\t" 60 | : "=m" (res) 61 | : "m" (a), "m" (bb) 62 | : "P0", "R0", "R1", "ASTAT" BFIN_HWLOOP0_REGS); 63 | return res; 64 | } 65 | 66 | #undef DIV32_16 67 | static inline spx_word16_t DIV32_16(spx_word32_t a, spx_word16_t b) 68 | { 69 | spx_word32_t res, bb; 70 | bb = b; 71 | /* Make the roundinf consistent with the C version 72 | (do we need to do that?)*/ 73 | if (a<0) 74 | a += (b-1); 75 | __asm__ ( 76 | "P0 = 15;\n\t" 77 | "R0 = %1;\n\t" 78 | "R1 = %2;\n\t" 79 | "R0 <<= 1;\n\t" 80 | "DIVS (R0, R1);\n\t" 81 | "LOOP divide%= LC0 = P0;\n\t" 82 | "LOOP_BEGIN divide%=;\n\t" 83 | "DIVQ (R0, R1);\n\t" 84 | "LOOP_END divide%=;\n\t" 85 | "R0 = R0.L;\n\t" 86 | "%0 = R0;\n\t" 87 | : "=m" (res) 88 | : "m" (a), "m" (bb) 89 | : "P0", "R0", "R1", "ASTAT" BFIN_HWLOOP0_REGS); 90 | return res; 91 | } 92 | 93 | #undef MAX16 94 | static inline spx_word16_t MAX16(spx_word16_t a, spx_word16_t b) 95 | { 96 | spx_word32_t res; 97 | __asm__ ( 98 | "%1 = %1.L (X);\n\t" 99 | "%2 = %2.L (X);\n\t" 100 | "%0 = MAX(%1,%2);" 101 | : "=d" (res) 102 | : "%d" (a), "d" (b) 103 | : "ASTAT" 104 | ); 105 | return res; 106 | } 107 | 108 | #undef MULT16_32_Q15 109 | static inline spx_word32_t MULT16_32_Q15(spx_word16_t a, spx_word32_t b) 110 | { 111 | spx_word32_t res; 112 | __asm__ 113 | ( 114 | "A1 = %2.L*%1.L (M);\n\t" 115 | "A1 = A1 >>> 15;\n\t" 116 | "%0 = (A1 += %2.L*%1.H) ;\n\t" 117 | : "=&W" (res), "=&d" (b) 118 | : "d" (a), "1" (b) 119 | : "A1", "ASTAT" 120 | ); 121 | return res; 122 | } 123 | 124 | #undef MAC16_32_Q15 125 | static inline spx_word32_t MAC16_32_Q15(spx_word32_t c, spx_word16_t a, spx_word32_t b) 126 | { 127 | spx_word32_t res; 128 | __asm__ 129 | ( 130 | "A1 = %2.L*%1.L (M);\n\t" 131 | "A1 = A1 >>> 15;\n\t" 132 | "%0 = (A1 += %2.L*%1.H);\n\t" 133 | "%0 = %0 + %4;\n\t" 134 | : "=&W" (res), "=&d" (b) 135 | : "d" (a), "1" (b), "d" (c) 136 | : "A1", "ASTAT" 137 | ); 138 | return res; 139 | } 140 | 141 | #undef MULT16_32_Q14 142 | static inline spx_word32_t MULT16_32_Q14(spx_word16_t a, spx_word32_t b) 143 | { 144 | spx_word32_t res; 145 | __asm__ 146 | ( 147 | "%2 <<= 1;\n\t" 148 | "A1 = %1.L*%2.L (M);\n\t" 149 | "A1 = A1 >>> 15;\n\t" 150 | "%0 = (A1 += %1.L*%2.H);\n\t" 151 | : "=W" (res), "=d" (a), "=d" (b) 152 | : "1" (a), "2" (b) 153 | : "A1", "ASTAT" 154 | ); 155 | return res; 156 | } 157 | 158 | #undef MAC16_32_Q14 159 | static inline spx_word32_t MAC16_32_Q14(spx_word32_t c, spx_word16_t a, spx_word32_t b) 160 | { 161 | spx_word32_t res; 162 | __asm__ 163 | ( 164 | "%1 <<= 1;\n\t" 165 | "A1 = %2.L*%1.L (M);\n\t" 166 | "A1 = A1 >>> 15;\n\t" 167 | "%0 = (A1 += %2.L*%1.H);\n\t" 168 | "%0 = %0 + %4;\n\t" 169 | : "=&W" (res), "=&d" (b) 170 | : "d" (a), "1" (b), "d" (c) 171 | : "A1", "ASTAT" 172 | ); 173 | return res; 174 | } 175 | 176 | #endif 177 | -------------------------------------------------------------------------------- /src/speex/fixed_generic.h: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2003 Jean-Marc Valin */ 2 | /** 3 | @file fixed_generic.h 4 | @brief Generic fixed-point operations 5 | */ 6 | /* 7 | Redistribution and use in source and binary forms, with or without 8 | modification, are permitted provided that the following conditions 9 | are met: 10 | 11 | - Redistributions of source code must retain the above copyright 12 | notice, this list of conditions and the following disclaimer. 13 | 14 | - Redistributions in binary form must reproduce the above copyright 15 | notice, this list of conditions and the following disclaimer in the 16 | documentation and/or other materials provided with the distribution. 17 | 18 | - Neither the name of the Xiph.org Foundation nor the names of its 19 | contributors may be used to endorse or promote products derived from 20 | this software without specific prior written permission. 21 | 22 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 23 | ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 24 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 25 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR 26 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 27 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 28 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 29 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 30 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 31 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 32 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 | */ 34 | 35 | #ifndef FIXED_GENERIC_H 36 | #define FIXED_GENERIC_H 37 | 38 | #define QCONST16(x,bits) ((spx_word16_t)(.5+(x)*(((spx_word32_t)1)<<(bits)))) 39 | #define QCONST32(x,bits) ((spx_word32_t)(.5+(x)*(((spx_word32_t)1)<<(bits)))) 40 | 41 | #define NEG16(x) (-(x)) 42 | #define NEG32(x) (-(x)) 43 | #define EXTRACT16(x) ((spx_word16_t)(x)) 44 | #define EXTEND32(x) ((spx_word32_t)(x)) 45 | #define SHR16(a,shift) ((a) >> (shift)) 46 | #define SHL16(a,shift) ((a) << (shift)) 47 | #define SHR32(a,shift) ((a) >> (shift)) 48 | #define SHL32(a,shift) ((a) << (shift)) 49 | #define PSHR16(a,shift) (SHR16((a)+((1<<((shift))>>1)),shift)) 50 | #define PSHR32(a,shift) (SHR32((a)+((EXTEND32(1)<<((shift))>>1)),shift)) 51 | #define VSHR32(a, shift) (((shift)>0) ? SHR32(a, shift) : SHL32(a, -(shift))) 52 | #define SATURATE16(x,a) (((x)>(a) ? (a) : (x)<-(a) ? -(a) : (x))) 53 | #define SATURATE32(x,a) (((x)>(a) ? (a) : (x)<-(a) ? -(a) : (x))) 54 | 55 | #define SATURATE32PSHR(x,shift,a) (((x)>=(SHL32(a,shift))) ? (a) : \ 56 | (x)<=-(SHL32(a,shift)) ? -(a) : \ 57 | (PSHR32(x, shift))) 58 | 59 | #define SHR(a,shift) ((a) >> (shift)) 60 | #define SHL(a,shift) ((spx_word32_t)(a) << (shift)) 61 | #define PSHR(a,shift) (SHR((a)+((EXTEND32(1)<<((shift))>>1)),shift)) 62 | #define SATURATE(x,a) (((x)>(a) ? (a) : (x)<-(a) ? -(a) : (x))) 63 | 64 | 65 | #define ADD16(a,b) ((spx_word16_t)((spx_word16_t)(a)+(spx_word16_t)(b))) 66 | #define SUB16(a,b) ((spx_word16_t)(a)-(spx_word16_t)(b)) 67 | #define ADD32(a,b) ((spx_word32_t)(a)+(spx_word32_t)(b)) 68 | #define SUB32(a,b) ((spx_word32_t)(a)-(spx_word32_t)(b)) 69 | 70 | 71 | /* result fits in 16 bits */ 72 | #define MULT16_16_16(a,b) ((((spx_word16_t)(a))*((spx_word16_t)(b)))) 73 | 74 | /* (spx_word32_t)(spx_word16_t) gives TI compiler a hint that it's 16x16->32 multiply */ 75 | #define MULT16_16(a,b) (((spx_word32_t)(spx_word16_t)(a))*((spx_word32_t)(spx_word16_t)(b))) 76 | 77 | #define MAC16_16(c,a,b) (ADD32((c),MULT16_16((a),(b)))) 78 | #define MULT16_32_Q12(a,b) ADD32(MULT16_16((a),SHR((b),12)), SHR(MULT16_16((a),((b)&0x00000fff)),12)) 79 | #define MULT16_32_Q13(a,b) ADD32(MULT16_16((a),SHR((b),13)), SHR(MULT16_16((a),((b)&0x00001fff)),13)) 80 | #define MULT16_32_Q14(a,b) ADD32(MULT16_16((a),SHR((b),14)), SHR(MULT16_16((a),((b)&0x00003fff)),14)) 81 | 82 | #define MULT16_32_Q11(a,b) ADD32(MULT16_16((a),SHR((b),11)), SHR(MULT16_16((a),((b)&0x000007ff)),11)) 83 | #define MAC16_32_Q11(c,a,b) ADD32(c,ADD32(MULT16_16((a),SHR((b),11)), SHR(MULT16_16((a),((b)&0x000007ff)),11))) 84 | 85 | #define MULT16_32_P15(a,b) ADD32(MULT16_16((a),SHR((b),15)), PSHR(MULT16_16((a),((b)&0x00007fff)),15)) 86 | #define MULT16_32_Q15(a,b) ADD32(MULT16_16((a),SHR((b),15)), SHR(MULT16_16((a),((b)&0x00007fff)),15)) 87 | #define MAC16_32_Q15(c,a,b) ADD32(c,ADD32(MULT16_16((a),SHR((b),15)), SHR(MULT16_16((a),((b)&0x00007fff)),15))) 88 | 89 | 90 | #define MAC16_16_Q11(c,a,b) (ADD32((c),SHR(MULT16_16((a),(b)),11))) 91 | #define MAC16_16_Q13(c,a,b) (ADD32((c),SHR(MULT16_16((a),(b)),13))) 92 | #define MAC16_16_P13(c,a,b) (ADD32((c),SHR(ADD32(4096,MULT16_16((a),(b))),13))) 93 | 94 | #define MULT16_16_Q11_32(a,b) (SHR(MULT16_16((a),(b)),11)) 95 | #define MULT16_16_Q13(a,b) (SHR(MULT16_16((a),(b)),13)) 96 | #define MULT16_16_Q14(a,b) (SHR(MULT16_16((a),(b)),14)) 97 | #define MULT16_16_Q15(a,b) (SHR(MULT16_16((a),(b)),15)) 98 | 99 | #define MULT16_16_P13(a,b) (SHR(ADD32(4096,MULT16_16((a),(b))),13)) 100 | #define MULT16_16_P14(a,b) (SHR(ADD32(8192,MULT16_16((a),(b))),14)) 101 | #define MULT16_16_P15(a,b) (SHR(ADD32(16384,MULT16_16((a),(b))),15)) 102 | 103 | #define MUL_16_32_R15(a,bh,bl) ADD32(MULT16_16((a),(bh)), SHR(MULT16_16((a),(bl)),15)) 104 | 105 | #define DIV32_16(a,b) ((spx_word16_t)(((spx_word32_t)(a))/((spx_word16_t)(b)))) 106 | #define PDIV32_16(a,b) ((spx_word16_t)(((spx_word32_t)(a)+((spx_word16_t)(b)>>1))/((spx_word16_t)(b)))) 107 | #define DIV32(a,b) (((spx_word32_t)(a))/((spx_word32_t)(b))) 108 | #define PDIV32(a,b) (((spx_word32_t)(a)+((spx_word16_t)(b)>>1))/((spx_word32_t)(b))) 109 | 110 | #endif 111 | -------------------------------------------------------------------------------- /src/speex/resample_neon.h: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2007-2008 Jean-Marc Valin 2 | * Copyright (C) 2008 Thorvald Natvig 3 | * Copyright (C) 2011 Texas Instruments 4 | * author Jyri Sarha 5 | */ 6 | /** 7 | @file resample_neon.h 8 | @brief Resampler functions (NEON version) 9 | */ 10 | /* 11 | Redistribution and use in source and binary forms, with or without 12 | modification, are permitted provided that the following conditions 13 | are met: 14 | 15 | - Redistributions of source code must retain the above copyright 16 | notice, this list of conditions and the following disclaimer. 17 | 18 | - Redistributions in binary form must reproduce the above copyright 19 | notice, this list of conditions and the following disclaimer in the 20 | documentation and/or other materials provided with the distribution. 21 | 22 | - Neither the name of the Xiph.org Foundation nor the names of its 23 | contributors may be used to endorse or promote products derived from 24 | this software without specific prior written permission. 25 | 26 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 27 | ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 28 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 29 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR 30 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 31 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 32 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 33 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 34 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 35 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 36 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 37 | */ 38 | 39 | #include 40 | 41 | #ifdef FIXED_POINT 42 | #ifdef __thumb2__ 43 | static inline int32_t saturate_32bit_to_16bit(int32_t a) { 44 | int32_t ret; 45 | asm ("ssat %[ret], #16, %[a]" 46 | : [ret] "=&r" (ret) 47 | : [a] "r" (a) 48 | : ); 49 | return ret; 50 | } 51 | #else 52 | static inline int32_t saturate_32bit_to_16bit(int32_t a) { 53 | int32_t ret; 54 | asm ("vmov.s32 d0[0], %[a]\n" 55 | "vqmovn.s32 d0, q0\n" 56 | "vmov.s16 %[ret], d0[0]\n" 57 | : [ret] "=&r" (ret) 58 | : [a] "r" (a) 59 | : "q0"); 60 | return ret; 61 | } 62 | #endif 63 | #undef WORD2INT 64 | #define WORD2INT(x) (saturate_32bit_to_16bit(x)) 65 | 66 | #define OVERRIDE_INNER_PRODUCT_SINGLE 67 | /* Only works when len % 4 == 0 */ 68 | static inline int32_t inner_product_single(const int16_t *a, const int16_t *b, unsigned int len) 69 | { 70 | int32_t ret; 71 | uint32_t remainder = len % 16; 72 | len = len - remainder; 73 | 74 | asm volatile (" cmp %[len], #0\n" 75 | " bne 1f\n" 76 | " vld1.16 {d16}, [%[b]]!\n" 77 | " vld1.16 {d20}, [%[a]]!\n" 78 | " subs %[remainder], %[remainder], #4\n" 79 | " vmull.s16 q0, d16, d20\n" 80 | " beq 5f\n" 81 | " b 4f\n" 82 | "1:" 83 | " vld1.16 {d16, d17, d18, d19}, [%[b]]!\n" 84 | " vld1.16 {d20, d21, d22, d23}, [%[a]]!\n" 85 | " subs %[len], %[len], #16\n" 86 | " vmull.s16 q0, d16, d20\n" 87 | " vmlal.s16 q0, d17, d21\n" 88 | " vmlal.s16 q0, d18, d22\n" 89 | " vmlal.s16 q0, d19, d23\n" 90 | " beq 3f\n" 91 | "2:" 92 | " vld1.16 {d16, d17, d18, d19}, [%[b]]!\n" 93 | " vld1.16 {d20, d21, d22, d23}, [%[a]]!\n" 94 | " subs %[len], %[len], #16\n" 95 | " vmlal.s16 q0, d16, d20\n" 96 | " vmlal.s16 q0, d17, d21\n" 97 | " vmlal.s16 q0, d18, d22\n" 98 | " vmlal.s16 q0, d19, d23\n" 99 | " bne 2b\n" 100 | "3:" 101 | " cmp %[remainder], #0\n" 102 | " beq 5f\n" 103 | "4:" 104 | " vld1.16 {d16}, [%[b]]!\n" 105 | " vld1.16 {d20}, [%[a]]!\n" 106 | " subs %[remainder], %[remainder], #4\n" 107 | " vmlal.s16 q0, d16, d20\n" 108 | " bne 4b\n" 109 | "5:" 110 | " vaddl.s32 q0, d0, d1\n" 111 | " vadd.s64 d0, d0, d1\n" 112 | " vqmovn.s64 d0, q0\n" 113 | " vqrshrn.s32 d0, q0, #15\n" 114 | " vmov.s16 %[ret], d0[0]\n" 115 | : [ret] "=&r" (ret), [a] "+r" (a), [b] "+r" (b), 116 | [len] "+r" (len), [remainder] "+r" (remainder) 117 | : 118 | : "cc", "q0", 119 | "d16", "d17", "d18", "d19", 120 | "d20", "d21", "d22", "d23"); 121 | 122 | return ret; 123 | } 124 | #elif defined(FLOATING_POINT) 125 | 126 | static inline int32_t saturate_float_to_16bit(float a) { 127 | int32_t ret; 128 | asm ("vmov.f32 d0[0], %[a]\n" 129 | "vcvt.s32.f32 d0, d0, #15\n" 130 | "vqrshrn.s32 d0, q0, #15\n" 131 | "vmov.s16 %[ret], d0[0]\n" 132 | : [ret] "=&r" (ret) 133 | : [a] "r" (a) 134 | : "q0"); 135 | return ret; 136 | } 137 | #undef WORD2INT 138 | #define WORD2INT(x) (saturate_float_to_16bit(x)) 139 | 140 | #define OVERRIDE_INNER_PRODUCT_SINGLE 141 | /* Only works when len % 4 == 0 */ 142 | static inline float inner_product_single(const float *a, const float *b, unsigned int len) 143 | { 144 | float ret; 145 | uint32_t remainder = len % 16; 146 | len = len - remainder; 147 | 148 | asm volatile (" cmp %[len], #0\n" 149 | " bne 1f\n" 150 | " vld1.32 {q4}, [%[b]]!\n" 151 | " vld1.32 {q8}, [%[a]]!\n" 152 | " subs %[remainder], %[remainder], #4\n" 153 | " vmul.f32 q0, q4, q8\n" 154 | " bne 4f\n" 155 | " b 5f\n" 156 | "1:" 157 | " vld1.32 {q4, q5}, [%[b]]!\n" 158 | " vld1.32 {q8, q9}, [%[a]]!\n" 159 | " vld1.32 {q6, q7}, [%[b]]!\n" 160 | " vld1.32 {q10, q11}, [%[a]]!\n" 161 | " subs %[len], %[len], #16\n" 162 | " vmul.f32 q0, q4, q8\n" 163 | " vmul.f32 q1, q5, q9\n" 164 | " vmul.f32 q2, q6, q10\n" 165 | " vmul.f32 q3, q7, q11\n" 166 | " beq 3f\n" 167 | "2:" 168 | " vld1.32 {q4, q5}, [%[b]]!\n" 169 | " vld1.32 {q8, q9}, [%[a]]!\n" 170 | " vld1.32 {q6, q7}, [%[b]]!\n" 171 | " vld1.32 {q10, q11}, [%[a]]!\n" 172 | " subs %[len], %[len], #16\n" 173 | " vmla.f32 q0, q4, q8\n" 174 | " vmla.f32 q1, q5, q9\n" 175 | " vmla.f32 q2, q6, q10\n" 176 | " vmla.f32 q3, q7, q11\n" 177 | " bne 2b\n" 178 | "3:" 179 | " vadd.f32 q4, q0, q1\n" 180 | " vadd.f32 q5, q2, q3\n" 181 | " cmp %[remainder], #0\n" 182 | " vadd.f32 q0, q4, q5\n" 183 | " beq 5f\n" 184 | "4:" 185 | " vld1.32 {q6}, [%[b]]!\n" 186 | " vld1.32 {q10}, [%[a]]!\n" 187 | " subs %[remainder], %[remainder], #4\n" 188 | " vmla.f32 q0, q6, q10\n" 189 | " bne 4b\n" 190 | "5:" 191 | " vadd.f32 d0, d0, d1\n" 192 | " vpadd.f32 d0, d0, d0\n" 193 | " vmov.f32 %[ret], d0[0]\n" 194 | : [ret] "=&r" (ret), [a] "+r" (a), [b] "+r" (b), 195 | [len] "+l" (len), [remainder] "+l" (remainder) 196 | : 197 | : "cc", "q0", "q1", "q2", "q3", "q4", "q5", "q6", "q7", "q8", 198 | "q9", "q10", "q11"); 199 | return ret; 200 | } 201 | #endif 202 | -------------------------------------------------------------------------------- /src/speex/resample_sse.h: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2007-2008 Jean-Marc Valin 2 | * Copyright (C) 2008 Thorvald Natvig 3 | */ 4 | /** 5 | @file resample_sse.h 6 | @brief Resampler functions (SSE version) 7 | */ 8 | /* 9 | Redistribution and use in source and binary forms, with or without 10 | modification, are permitted provided that the following conditions 11 | are met: 12 | 13 | - Redistributions of source code must retain the above copyright 14 | notice, this list of conditions and the following disclaimer. 15 | 16 | - Redistributions in binary form must reproduce the above copyright 17 | notice, this list of conditions and the following disclaimer in the 18 | documentation and/or other materials provided with the distribution. 19 | 20 | - Neither the name of the Xiph.org Foundation nor the names of its 21 | contributors may be used to endorse or promote products derived from 22 | this software without specific prior written permission. 23 | 24 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 25 | ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 26 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 27 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR 28 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 29 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 30 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 31 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 32 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 33 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 34 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 35 | */ 36 | 37 | #include 38 | 39 | #define OVERRIDE_INNER_PRODUCT_SINGLE 40 | static inline float inner_product_single(const float *a, const float *b, unsigned int len) 41 | { 42 | int i; 43 | float ret; 44 | __m128 sum = _mm_setzero_ps(); 45 | for (i=0;i 76 | #define OVERRIDE_INNER_PRODUCT_DOUBLE 77 | 78 | static inline double inner_product_double(const float *a, const float *b, unsigned int len) 79 | { 80 | int i; 81 | double ret; 82 | __m128d sum = _mm_setzero_pd(); 83 | __m128 t; 84 | for (i=0;i 41 | # else 42 | # ifdef HAVE_ALLOCA_H 43 | # include 44 | # else 45 | # include 46 | # endif 47 | # endif 48 | #endif 49 | 50 | /** 51 | * @def ALIGN(stack, size) 52 | * 53 | * Aligns the stack to a 'size' boundary 54 | * 55 | * @param stack Stack 56 | * @param size New size boundary 57 | */ 58 | 59 | /** 60 | * @def PUSH(stack, size, type) 61 | * 62 | * Allocates 'size' elements of type 'type' on the stack 63 | * 64 | * @param stack Stack 65 | * @param size Number of elements 66 | * @param type Type of element 67 | */ 68 | 69 | /** 70 | * @def VARDECL(var) 71 | * 72 | * Declare variable on stack 73 | * 74 | * @param var Variable to declare 75 | */ 76 | 77 | /** 78 | * @def ALLOC(var, size, type) 79 | * 80 | * Allocate 'size' elements of 'type' on stack 81 | * 82 | * @param var Name of variable to allocate 83 | * @param size Number of elements 84 | * @param type Type of element 85 | */ 86 | 87 | #ifdef ENABLE_VALGRIND 88 | 89 | #include 90 | 91 | #define ALIGN(stack, size) ((stack) += ((size) - (long)(stack)) & ((size) - 1)) 92 | 93 | #define PUSH(stack, size, type) (VALGRIND_MAKE_NOACCESS(stack, 1000),ALIGN((stack),sizeof(type)),VALGRIND_MAKE_WRITABLE(stack, ((size)*sizeof(type))),(stack)+=((size)*sizeof(type)),(type*)((stack)-((size)*sizeof(type)))) 94 | 95 | #else 96 | 97 | #define ALIGN(stack, size) ((stack) += ((size) - (long)(stack)) & ((size) - 1)) 98 | 99 | #define PUSH(stack, size, type) (ALIGN((stack),sizeof(type)),(stack)+=((size)*sizeof(type)),(type*)((stack)-((size)*sizeof(type)))) 100 | 101 | #endif 102 | 103 | #if defined(VAR_ARRAYS) 104 | #define VARDECL(var) 105 | #define ALLOC(var, size, type) type var[size] 106 | #elif defined(USE_ALLOCA) 107 | #define VARDECL(var) var 108 | #define ALLOC(var, size, type) var = alloca(sizeof(type)*(size)) 109 | #else 110 | #define VARDECL(var) var 111 | #define ALLOC(var, size, type) var = PUSH(stack, size, type) 112 | #endif 113 | 114 | 115 | #endif 116 | --------------------------------------------------------------------------------