├── .gitattributes ├── .gitignore ├── .gitmodules ├── .travis.yml ├── Doxyfile ├── LICENSE ├── MSVC ├── Lua531 │ ├── Lua531.vcxproj │ └── Lua531.vcxproj.filters ├── Lua531Compiler │ ├── Lua531Compiler.vcxproj │ └── Lua531Compiler.vcxproj.filters ├── OpenVSM.sln ├── OpenVSM.vcxproj ├── OpenVSM.vcxproj.filters └── SystemLua │ ├── SystemLua.vcxproj │ └── SystemLua.vcxproj.filters ├── Makefile ├── README.md ├── bin2source ├── Makefile ├── bin2source.vcxproj └── main.cpp ├── dll ├── UserManual-RUS.odt ├── UserManual-RUS.pdf └── nand.gif ├── examples └── NAND │ ├── README.md │ ├── device.txt │ ├── nand.lua │ └── nand.pdsprj ├── externals ├── installer │ ├── README.md │ └── openvsm.iss ├── lua │ ├── README │ ├── doc │ │ ├── logo.gif │ │ ├── lua.1 │ │ ├── luac.1 │ │ └── osi-certified-72x60.png │ └── src │ │ ├── Makefile │ │ ├── lapi.c │ │ ├── lapi.h │ │ ├── lauxlib.c │ │ ├── lauxlib.h │ │ ├── lbaselib.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 │ │ ├── ljumptab.h │ │ ├── llex.c │ │ ├── llex.h │ │ ├── llimits.h │ │ ├── lmathlib.c │ │ ├── lmem.c │ │ ├── lmem.h │ │ ├── loadlib.c │ │ ├── lobject.c │ │ ├── lobject.h │ │ ├── lopcodes.c │ │ ├── lopcodes.h │ │ ├── lopnames.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 └── lua_version.txt ├── include ├── _version.h ├── bus.h ├── cbind.h ├── defines.h ├── enums.h ├── luabind.h ├── pin.h ├── text.h ├── uthash.h ├── utils.h ├── vdmapi.h ├── version.h ├── vsmapi.h ├── vsmclasses.h └── vsmobj.h ├── relgen.sh └── src ├── Makefile ├── bindings ├── cbind.c └── luabind.c ├── device └── device.lua ├── lua_bus.c ├── lua_pin.c ├── lua_vsmobj.c ├── modules ├── module_bus.lua ├── module_custom.lua ├── module_events.lua ├── module_fifo.lua ├── module_pin.lua ├── module_uart.lua └── modules.h ├── openvsm.rc ├── subsys └── sound │ ├── main.c │ └── sound.c ├── utils.c ├── vsmapi.c └── wincompat.c /.gitattributes: -------------------------------------------------------------------------------- 1 | *.h eol=crlf 2 | *.hpp eol=crlf 3 | *.cpp eol=crlf 4 | *.c eol=crlf 5 | *.rc eol=crlf 6 | *.vcproj eol=crlf 7 | *.bat eol=crlf 8 | *.sln eol=crlf 9 | *.ico -text -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /src/modules/module_pin.lua.mod.c 2 | /src/modules/module_bus.lua.mod.c 3 | /src/modules/module_custom.lua.mod.c 4 | /src/modules/module_events.lua.mod.c 5 | 6 | # Object files 7 | *.o 8 | *.ko 9 | *.obj 10 | *.elf 11 | *.mod 12 | *.res 13 | 14 | # Precompiled Headers 15 | *.gch 16 | *.pch 17 | 18 | # Libraries 19 | *.lib 20 | *.a 21 | *.la 22 | *.lo 23 | 24 | # Shared objects (inc. Windows DLLs) 25 | *.dll 26 | *.so 27 | *.so.* 28 | *.dylib 29 | 30 | # Executables 31 | *.exe 32 | *.out 33 | *.app 34 | *.i*86 35 | *.x86_64 36 | *.hex 37 | *.css 38 | *.html 39 | 40 | # Debug files 41 | *.dSYM/ 42 | *.pdb 43 | *.ilk 44 | *.exp 45 | 46 | #Archives 47 | *.zip 48 | 49 | ## Ignore Visual Studio temporary files, build results, and 50 | ## files generated by popular Visual Studio add-ons. 51 | 52 | # User-specific files 53 | *.sdf 54 | *.suo 55 | *.user 56 | *.userosscache 57 | *.sln.docstates 58 | 59 | # User-specific files (MonoDevelop/Xamarin Studio) 60 | *.userprefs 61 | 62 | # Build results 63 | [Dd]ebug/ 64 | [Dd]ebugPublic/ 65 | [Rr]elease/ 66 | [Rr]eleases/ 67 | x64/ 68 | x86/ 69 | build/ 70 | bld/ 71 | [Bb]in/ 72 | [Oo]bj/ 73 | 74 | # Visual Studio 2015 cache/options directory 75 | .vs/ 76 | 77 | # MSTest test Results 78 | [Tt]est[Rr]esult*/ 79 | [Bb]uild[Ll]og.* 80 | 81 | # Visual C++ cache files 82 | ipch/ 83 | *.aps 84 | *.ncb 85 | *.opensdf 86 | *.sdf 87 | *.cachefile 88 | 89 | # Visual Studio profiler 90 | *.psess 91 | *.vsp 92 | *.vspx 93 | *.sap 94 | 95 | # DotCover is a Code Coverage Tool 96 | *.dotCover 97 | 98 | # Web workbench (sass) 99 | .sass-cache/ 100 | 101 | # Installshield output folder 102 | [Ee]xpress/ 103 | 104 | # DocProject is a documentation generator add-in 105 | DocProject/buildhelp/ 106 | DocProject/Help/*.HxT 107 | DocProject/Help/*.HxC 108 | DocProject/Help/*.hhc 109 | DocProject/Help/*.hhk 110 | DocProject/Help/*.hhp 111 | DocProject/Help/Html2 112 | DocProject/Help/html 113 | 114 | # Windows Store app package directory 115 | AppPackages/ 116 | 117 | # Visual Studio cache files 118 | # files ending in .cache can be ignored 119 | *.[Cc]ache 120 | # but keep track of directories ending in .cache 121 | !*.[Cc]ache/ 122 | 123 | # Backup & report files from converting an old project file 124 | # to a newer Visual Studio version. Backup files are not needed, 125 | # because we have git ;-) 126 | _UpgradeReport_Files/ 127 | Backup*/ 128 | UpgradeLog*.XML 129 | UpgradeLog*.htm 130 | 131 | # Microsoft Fakes 132 | FakesAssemblies/ 133 | 134 | # Visual Studio 6 build log 135 | *.plg 136 | 137 | # Visual Studio 6 workspace options file 138 | *.opt 139 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pugnator/openvsm/c28a7a8210ea2fabc57951ce33cfb3b047d4348d/.gitmodules -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: c 2 | include: 3 | # cross-compile using mingw 4 | - compiler: ": w64" 5 | env: PLATFORM="mingw32" ARCH="x86" BITSIZE=32 HOST="i686" 6 | 7 | install: 8 | - sudo apt-get update -qq 9 | - sudo apt-get install mingw-w64 -y -qq 10 | 11 | script: 12 | - make 13 | 14 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (C) 2015 Lavrentiy Ivanov 2 | 3 | This program is free software; you can redistribute it and/or 4 | modify it under the terms of the GNU General Public License 5 | as published by the Free Software Foundation; either version 2 6 | of the License, or (at your option) any later version. 7 | 8 | This program is distributed in the hope that it will be useful, 9 | but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | GNU General Public License for more details. 12 | 13 | You should have received a copy of the GNU General Public License 14 | along with this program; if not, write to the Free Software 15 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -------------------------------------------------------------------------------- /MSVC/Lua531/Lua531.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | Source Files 20 | 21 | 22 | Source Files 23 | 24 | 25 | Source Files 26 | 27 | 28 | Source Files 29 | 30 | 31 | Source Files 32 | 33 | 34 | Source Files 35 | 36 | 37 | Source Files 38 | 39 | 40 | Source Files 41 | 42 | 43 | Source Files 44 | 45 | 46 | Source Files 47 | 48 | 49 | Source Files 50 | 51 | 52 | Source Files 53 | 54 | 55 | Source Files 56 | 57 | 58 | Source Files 59 | 60 | 61 | Source Files 62 | 63 | 64 | Source Files 65 | 66 | 67 | Source Files 68 | 69 | 70 | Source Files 71 | 72 | 73 | Source Files 74 | 75 | 76 | Source Files 77 | 78 | 79 | Source Files 80 | 81 | 82 | Source Files 83 | 84 | 85 | Source Files 86 | 87 | 88 | Source Files 89 | 90 | 91 | Source Files 92 | 93 | 94 | Source Files 95 | 96 | 97 | Source Files 98 | 99 | 100 | Source Files 101 | 102 | 103 | Source Files 104 | 105 | 106 | Source Files 107 | 108 | 109 | Source Files 110 | 111 | 112 | Source Files 113 | 114 | 115 | Source Files 116 | 117 | 118 | Source Files 119 | 120 | 121 | 122 | 123 | Header Files 124 | 125 | 126 | Header Files 127 | 128 | 129 | Header Files 130 | 131 | 132 | Header Files 133 | 134 | 135 | Header Files 136 | 137 | 138 | Header Files 139 | 140 | 141 | Header Files 142 | 143 | 144 | Header Files 145 | 146 | 147 | Header Files 148 | 149 | 150 | Header Files 151 | 152 | 153 | Header Files 154 | 155 | 156 | Header Files 157 | 158 | 159 | Header Files 160 | 161 | 162 | Header Files 163 | 164 | 165 | Header Files 166 | 167 | 168 | Header Files 169 | 170 | 171 | Header Files 172 | 173 | 174 | Header Files 175 | 176 | 177 | Header Files 178 | 179 | 180 | Header Files 181 | 182 | 183 | Header Files 184 | 185 | 186 | Header Files 187 | 188 | 189 | Header Files 190 | 191 | 192 | Header Files 193 | 194 | 195 | Header Files 196 | 197 | 198 | Header Files 199 | 200 | 201 | -------------------------------------------------------------------------------- /MSVC/Lua531Compiler/Lua531Compiler.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | Header Files 20 | 21 | 22 | Header Files 23 | 24 | 25 | Header Files 26 | 27 | 28 | Header Files 29 | 30 | 31 | Header Files 32 | 33 | 34 | Header Files 35 | 36 | 37 | Header Files 38 | 39 | 40 | Header Files 41 | 42 | 43 | Header Files 44 | 45 | 46 | Header Files 47 | 48 | 49 | Header Files 50 | 51 | 52 | Header Files 53 | 54 | 55 | Header Files 56 | 57 | 58 | Header Files 59 | 60 | 61 | Header Files 62 | 63 | 64 | Header Files 65 | 66 | 67 | Header Files 68 | 69 | 70 | Header Files 71 | 72 | 73 | Header Files 74 | 75 | 76 | Header Files 77 | 78 | 79 | Header Files 80 | 81 | 82 | Header Files 83 | 84 | 85 | Header Files 86 | 87 | 88 | Header Files 89 | 90 | 91 | Header Files 92 | 93 | 94 | Header Files 95 | 96 | 97 | 98 | 99 | Source Files 100 | 101 | 102 | -------------------------------------------------------------------------------- /MSVC/OpenVSM.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 14 4 | VisualStudioVersion = 14.0.23107.0 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "OpenVSM", "OpenVSM.vcxproj", "{7B78D7D8-2CEC-47F7-9FD4-F5FE8C662573}" 7 | ProjectSection(ProjectDependencies) = postProject 8 | {7C739CC0-8DCB-484E-8461-7BEDD67070C6} = {7C739CC0-8DCB-484E-8461-7BEDD67070C6} 9 | {A8AA0ACD-E43D-4B00-9A99-3417DB54ACE4} = {A8AA0ACD-E43D-4B00-9A99-3417DB54ACE4} 10 | {18468AE6-2224-4D77-88BF-6AE2240B5C82} = {18468AE6-2224-4D77-88BF-6AE2240B5C82} 11 | EndProjectSection 12 | EndProject 13 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "bin2source", "..\bin2source\bin2source.vcxproj", "{18468AE6-2224-4D77-88BF-6AE2240B5C82}" 14 | ProjectSection(ProjectDependencies) = postProject 15 | {7C739CC0-8DCB-484E-8461-7BEDD67070C6} = {7C739CC0-8DCB-484E-8461-7BEDD67070C6} 16 | {A8AA0ACD-E43D-4B00-9A99-3417DB54ACE4} = {A8AA0ACD-E43D-4B00-9A99-3417DB54ACE4} 17 | EndProjectSection 18 | EndProject 19 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Lua531", "Lua531\Lua531.vcxproj", "{A8AA0ACD-E43D-4B00-9A99-3417DB54ACE4}" 20 | EndProject 21 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Lua531Compiler", "Lua531Compiler\Lua531Compiler.vcxproj", "{7C739CC0-8DCB-484E-8461-7BEDD67070C6}" 22 | ProjectSection(ProjectDependencies) = postProject 23 | {A8AA0ACD-E43D-4B00-9A99-3417DB54ACE4} = {A8AA0ACD-E43D-4B00-9A99-3417DB54ACE4} 24 | EndProjectSection 25 | EndProject 26 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{A5771D7A-EDB5-4424-AB87-9F3B8799A565}" 27 | ProjectSection(SolutionItems) = preProject 28 | Performance1.psess = Performance1.psess 29 | EndProjectSection 30 | EndProject 31 | Global 32 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 33 | Debug|Win32 = Debug|Win32 34 | Debug|x64 = Debug|x64 35 | Release|Win32 = Release|Win32 36 | Release|x64 = Release|x64 37 | EndGlobalSection 38 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 39 | {7B78D7D8-2CEC-47F7-9FD4-F5FE8C662573}.Debug|Win32.ActiveCfg = Debug|Win32 40 | {7B78D7D8-2CEC-47F7-9FD4-F5FE8C662573}.Debug|Win32.Build.0 = Debug|Win32 41 | {7B78D7D8-2CEC-47F7-9FD4-F5FE8C662573}.Debug|x64.ActiveCfg = Debug|Win32 42 | {7B78D7D8-2CEC-47F7-9FD4-F5FE8C662573}.Release|Win32.ActiveCfg = Release|Win32 43 | {7B78D7D8-2CEC-47F7-9FD4-F5FE8C662573}.Release|Win32.Build.0 = Release|Win32 44 | {7B78D7D8-2CEC-47F7-9FD4-F5FE8C662573}.Release|x64.ActiveCfg = Release|Win32 45 | {18468AE6-2224-4D77-88BF-6AE2240B5C82}.Debug|Win32.ActiveCfg = Debug|Win32 46 | {18468AE6-2224-4D77-88BF-6AE2240B5C82}.Debug|Win32.Build.0 = Debug|Win32 47 | {18468AE6-2224-4D77-88BF-6AE2240B5C82}.Debug|x64.ActiveCfg = Debug|x64 48 | {18468AE6-2224-4D77-88BF-6AE2240B5C82}.Debug|x64.Build.0 = Debug|x64 49 | {18468AE6-2224-4D77-88BF-6AE2240B5C82}.Release|Win32.ActiveCfg = Release|Win32 50 | {18468AE6-2224-4D77-88BF-6AE2240B5C82}.Release|Win32.Build.0 = Release|Win32 51 | {18468AE6-2224-4D77-88BF-6AE2240B5C82}.Release|x64.ActiveCfg = Release|x64 52 | {18468AE6-2224-4D77-88BF-6AE2240B5C82}.Release|x64.Build.0 = Release|x64 53 | {A8AA0ACD-E43D-4B00-9A99-3417DB54ACE4}.Debug|Win32.ActiveCfg = Debug|Win32 54 | {A8AA0ACD-E43D-4B00-9A99-3417DB54ACE4}.Debug|Win32.Build.0 = Debug|Win32 55 | {A8AA0ACD-E43D-4B00-9A99-3417DB54ACE4}.Debug|x64.ActiveCfg = Debug|x64 56 | {A8AA0ACD-E43D-4B00-9A99-3417DB54ACE4}.Debug|x64.Build.0 = Debug|x64 57 | {A8AA0ACD-E43D-4B00-9A99-3417DB54ACE4}.Release|Win32.ActiveCfg = Release|Win32 58 | {A8AA0ACD-E43D-4B00-9A99-3417DB54ACE4}.Release|Win32.Build.0 = Release|Win32 59 | {A8AA0ACD-E43D-4B00-9A99-3417DB54ACE4}.Release|x64.ActiveCfg = Release|x64 60 | {A8AA0ACD-E43D-4B00-9A99-3417DB54ACE4}.Release|x64.Build.0 = Release|x64 61 | {7C739CC0-8DCB-484E-8461-7BEDD67070C6}.Debug|Win32.ActiveCfg = Debug|Win32 62 | {7C739CC0-8DCB-484E-8461-7BEDD67070C6}.Debug|Win32.Build.0 = Debug|Win32 63 | {7C739CC0-8DCB-484E-8461-7BEDD67070C6}.Debug|x64.ActiveCfg = Debug|x64 64 | {7C739CC0-8DCB-484E-8461-7BEDD67070C6}.Debug|x64.Build.0 = Debug|x64 65 | {7C739CC0-8DCB-484E-8461-7BEDD67070C6}.Release|Win32.ActiveCfg = Release|Win32 66 | {7C739CC0-8DCB-484E-8461-7BEDD67070C6}.Release|Win32.Build.0 = Release|Win32 67 | {7C739CC0-8DCB-484E-8461-7BEDD67070C6}.Release|x64.ActiveCfg = Release|x64 68 | {7C739CC0-8DCB-484E-8461-7BEDD67070C6}.Release|x64.Build.0 = Release|x64 69 | EndGlobalSection 70 | GlobalSection(SolutionProperties) = preSolution 71 | HideSolutionNode = FALSE 72 | EndGlobalSection 73 | EndGlobal 74 | -------------------------------------------------------------------------------- /MSVC/OpenVSM.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav 15 | 16 | 17 | 18 | 19 | Source Files 20 | 21 | 22 | Source Files 23 | 24 | 25 | Source Files 26 | 27 | 28 | Source Files 29 | 30 | 31 | Source Files 32 | 33 | 34 | Source Files 35 | 36 | 37 | Source Files 38 | 39 | 40 | Source Files 41 | 42 | 43 | Source Files 44 | 45 | 46 | Source Files 47 | 48 | 49 | Source Files 50 | 51 | 52 | Source Files 53 | 54 | 55 | Source Files 56 | 57 | 58 | 59 | 60 | Header Files 61 | 62 | 63 | Header Files 64 | 65 | 66 | Header Files 67 | 68 | 69 | Header Files 70 | 71 | 72 | Header Files 73 | 74 | 75 | Header Files 76 | 77 | 78 | Header Files 79 | 80 | 81 | Header Files 82 | 83 | 84 | Header Files 85 | 86 | 87 | Header Files 88 | 89 | 90 | Header Files 91 | 92 | 93 | Header Files 94 | 95 | 96 | Header Files 97 | 98 | 99 | Header Files 100 | 101 | 102 | Header Files 103 | 104 | 105 | Header Files 106 | 107 | 108 | Header Files 109 | 110 | 111 | Header Files 112 | 113 | 114 | Header Files 115 | 116 | 117 | Header Files 118 | 119 | 120 | Header Files 121 | 122 | 123 | Header Files 124 | 125 | 126 | Header Files 127 | 128 | 129 | Header Files 130 | 131 | 132 | Header Files 133 | 134 | 135 | Header Files 136 | 137 | 138 | Header Files 139 | 140 | 141 | Header Files 142 | 143 | 144 | Header Files 145 | 146 | 147 | Header Files 148 | 149 | 150 | Header Files 151 | 152 | 153 | Header Files 154 | 155 | 156 | Header Files 157 | 158 | 159 | Header Files 160 | 161 | 162 | Header Files 163 | 164 | 165 | Header Files 166 | 167 | 168 | Header Files 169 | 170 | 171 | Header Files 172 | 173 | 174 | Header Files 175 | 176 | 177 | Header Files 178 | 179 | 180 | Header Files 181 | 182 | 183 | Header Files 184 | 185 | 186 | Header Files 187 | 188 | 189 | 190 | 191 | Resource Files 192 | 193 | 194 | -------------------------------------------------------------------------------- /MSVC/SystemLua/SystemLua.vcxproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Release 10 | Win32 11 | 12 | 13 | Debug 14 | x64 15 | 16 | 17 | Release 18 | x64 19 | 20 | 21 | 22 | {CFEBDEF0-DDBE-49CB-BB56-184FA5ED5B65} 23 | SystemLua 24 | 8.1 25 | 26 | 27 | 28 | Application 29 | true 30 | v140 31 | MultiByte 32 | 33 | 34 | Application 35 | false 36 | v140 37 | true 38 | MultiByte 39 | 40 | 41 | Application 42 | true 43 | v140 44 | MultiByte 45 | 46 | 47 | Application 48 | false 49 | v140 50 | true 51 | MultiByte 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | C:\Users\pugnator\Dropbox\Dev\IBM-PC\Lin32\openvsm\externals\lua-5.3.1\src;$(IncludePath) 73 | 74 | 75 | 76 | Level3 77 | Disabled 78 | true 79 | 80 | 81 | true 82 | 83 | 84 | 85 | 86 | Level3 87 | Disabled 88 | true 89 | 90 | 91 | true 92 | 93 | 94 | 95 | 96 | Level3 97 | MaxSpeed 98 | true 99 | true 100 | true 101 | 102 | 103 | true 104 | true 105 | true 106 | 107 | 108 | 109 | 110 | Level3 111 | MaxSpeed 112 | true 113 | true 114 | true 115 | 116 | 117 | true 118 | true 119 | true 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | -------------------------------------------------------------------------------- /MSVC/SystemLua/SystemLua.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | Source Files 20 | 21 | 22 | Source Files 23 | 24 | 25 | 26 | 27 | Header Files 28 | 29 | 30 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | LUATOOLS="" 2 | 3 | ISCC := iscc 4 | 5 | ifdef SystemRoot 6 | MAKE := make 7 | RM := rm -f 8 | CP := copy 9 | LUATOOLS := win32lua 10 | FixPath = $(subst /,\,$1) 11 | else 12 | ifeq ($(shell uname), Linux) 13 | RM = rm -f 14 | CP = cp 15 | MAKE=make 16 | FixPath = $1 17 | LUATOOLS=linlua 18 | else ifeq ($(OS), Windows_NT) 19 | MAKE := make 20 | RM := rm -f 21 | CP := copy 22 | LUATOOLS := win32lua 23 | FixPath := $(subst /,\,$1) 24 | endif 25 | endif 26 | 27 | all: 28 | mkdir -p tools 29 | mkdir -p dll 30 | $(MAKE) tools 31 | $(MAKE) $(LUATOOLS) 32 | $(MAKE) -C src 33 | 34 | clean: 35 | $(MAKE) -C bin2source clean 36 | $(MAKE) -C src clean 37 | $(MAKE) -C externals/lua/src clean 38 | $(RM) tools/* 39 | 40 | tools: 41 | $(MAKE) -C bin2source 42 | 43 | linlua: 44 | $(MAKE) -C externals/lua/src linux 45 | $(CP) externals/lua/src/luac.exe tools/ 46 | $(MAKE) -C externals/lua/src clean 47 | $(MAKE) -C externals/lua/src mingw 48 | 49 | win32lua: 50 | $(MAKE) -C externals/lua/src mingw 51 | cp externals/lua/src/luac.exe tools 52 | 53 | innosetup: 54 | $(ISCC) externals/installer/openvsm.iss 55 | 56 | .PHONY: all clean tools innosetup win32lua linlua 57 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # OpenVSM is Lua bindings for Proteus 7/8 CAD 2 | [![Release][release-image]][releases] [![Wiki][wiki-img]][wiki] 3 | 4 | 5 | [release-image]: https://img.shields.io/badge/release-0.6.213-blue.svg?style=flat 6 | [releases]: https://github.com/Pugnator/openvsm/releases 7 | [wiki-img]: https://img.shields.io/badge/docs-Wiki-blue.svg 8 | [wiki]: https://github.com/Pugnator/openvsm/wiki 9 | 10 | 11 | Tested on Proteus 8.9 12 | 13 | Please report all issues you face in order to make this tool better 14 | 15 | ![Lua logo](http://www.lua.org/images/powered-by-lua.gif) 16 | 17 | Powered by Lua http://www.lua.org/ 18 | 19 | Documentation can be found at http://pugnator.github.io/openvsm 20 | 21 | Prebuilt DLL and symbols or installer are in [Release](https://github.com/Pugnator/openvsm/releases) section 22 | 23 | Written in C99 and gcc-ready (mingw/cygwin) for Linux and Windows 24 | 25 | - You don't need to recompile anything - one DLL for all models in Lua 26 | - You can create your model as a standalone DLL or use DLL and Lua script together while prototyping 27 | - You can write your own Lua scripts that will be precompiled and built-in into DLL 28 | - Function prototypes have similar syntax in C and Lua API 29 | - Designed with hope to make simulation as simple as possible for electronics enthusiasts 30 | 31 | 32 | Visit 'examples' directory for sample project files. There is no tutorial yet but I'm working on it 33 | 34 | Please kindly send all your remarks and ideas to my mail [o o kami (at) ma il.ru] or submit a bug or feature request 35 | 36 | There are plenty to do! 37 | 38 | Generally you need to compile DLL from the sources only if you want to include custom scripts. 39 | 40 | # Installation 41 | -------------- 42 | 43 | - Download OPenVSM MSI installer from `release` section 44 | - Run installer and install it 45 | - Visit `exmples` for some example projects 46 | 47 | How to build 48 | -------------- 49 | 50 | - Install mingw32 and cygwin for you platform 51 | - Install Lua 5.3 or higher 52 | - Clone: https://github.com/Pugnator/openvsm.git openvsm 53 | - Navigate to the openvsm directory 54 | - Issue "make" command in Linux or "mingw32-make" under Windows 55 | - Create environment variable containing path to the script directory, 56 | issuing the following command: 57 | 58 | ```bat 59 | setx LUAVSM "C:\script" 60 | ``` 61 | - In this case you should place your model script to c:\script directory 62 | 63 | # License 64 | ---- 65 | 66 | GPL 2 67 | -------------------------------------------------------------------------------- /bin2source/Makefile: -------------------------------------------------------------------------------- 1 | CURENV=$(shell gcc -dumpmachine) 2 | ifneq (, $(findstring mingw, $(CURENV))) 3 | MAKE=make 4 | CC:=gcc 5 | AR:=ar 6 | OBJCOPY:=objcopy 7 | STRIP:=strip 8 | WINRES:=windres 9 | else ifneq (, $(findstring linux, $(CURENV))) 10 | MAKE=make 11 | CC:=gcc 12 | AR:=ar 13 | OBJCOPY:=objcopy 14 | STRIP:=strip 15 | else 16 | exit 0 17 | endif 18 | 19 | BIN2SRC:=../tools/bin2source.exe 20 | 21 | SRC:=main.cpp 22 | 23 | CFLAGS:=-O0 -ggdb -g3 -std=gnu99 24 | 25 | OBJ=$(SRC:%.c=%.o) 26 | 27 | all: $(BIN2SRC) 28 | 29 | %.o: %.c 30 | $(CC) -c -o $@ $< $(CFLAGS) 31 | 32 | $(BIN2SRC): $(OBJ) 33 | $(CC) -o $@ $^ 34 | 35 | clean: 36 | @-rm -f $(BIN2SRC) *.o 37 | -------------------------------------------------------------------------------- /bin2source/bin2source.vcxproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Release 10 | Win32 11 | 12 | 13 | Debug 14 | x64 15 | 16 | 17 | Release 18 | x64 19 | 20 | 21 | 22 | {18468AE6-2224-4D77-88BF-6AE2240B5C82} 23 | Win32Proj 24 | bin2source 25 | 26 | 27 | 28 | Application 29 | true 30 | v141_xp 31 | NotSet 32 | 33 | 34 | Application 35 | false 36 | v141 37 | true 38 | Unicode 39 | 40 | 41 | Application 42 | true 43 | v141 44 | Unicode 45 | 46 | 47 | Application 48 | false 49 | v141 50 | true 51 | Unicode 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | true 73 | ..\tools 74 | 75 | 76 | true 77 | 78 | 79 | false 80 | 81 | 82 | false 83 | 84 | 85 | 86 | 87 | 88 | Level3 89 | Disabled 90 | WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) 91 | CompileAsC 92 | OnlyExplicitInline 93 | false 94 | None 95 | Default 96 | MultiThreaded 97 | false 98 | false 99 | 100 | 101 | Console 102 | true 103 | Shlwapi.lib;%(AdditionalDependencies) 104 | 105 | 106 | 107 | 108 | 109 | 110 | Level3 111 | Disabled 112 | _DEBUG;_CONSOLE;%(PreprocessorDefinitions) 113 | 114 | 115 | Console 116 | true 117 | 118 | 119 | 120 | 121 | Level3 122 | 123 | 124 | MaxSpeed 125 | true 126 | true 127 | WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) 128 | 129 | 130 | Console 131 | true 132 | true 133 | true 134 | 135 | 136 | 137 | 138 | Level3 139 | 140 | 141 | MaxSpeed 142 | true 143 | true 144 | NDEBUG;_CONSOLE;%(PreprocessorDefinitions) 145 | 146 | 147 | Console 148 | true 149 | true 150 | true 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | -------------------------------------------------------------------------------- /bin2source/main.cpp: -------------------------------------------------------------------------------- 1 | #define _CRT_SECURE_NO_WARNINGS 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | #if !defined MAX_PATH 11 | #define MAX_PATH 255 12 | #endif 13 | 14 | /** \brief The filename[ maximum path]. */ 15 | char filename[MAX_PATH] = {0}; 16 | 17 | 18 | /**********************************************************************************************//** 19 | * \fn void make_ident(char* name) 20 | * 21 | * \brief Makes an identifier. 22 | * 23 | * \author Pugnator 24 | * \date 11/21/2015 25 | * 26 | * \param [in,out] name If non-null, the name. 27 | **/ 28 | 29 | void 30 | make_ident(char* name) 31 | { 32 | strncpy(filename, basename(name), sizeof filename); 33 | for (char *p = filename; *p; p++) 34 | { 35 | if (!isalnum(*p)) 36 | { 37 | *p = '_'; 38 | } 39 | } 40 | } 41 | int 42 | main(int argc, char* argv[]) 43 | { 44 | unsigned char buf[BUFSIZ]; 45 | 46 | // if (argc < 2) 47 | { 48 | // fprintf(stderr, "Usage: %s binary_file > output_file\n", argv[0]); 49 | // return -1; 50 | } 51 | 52 | FILE *fd = fopen(argv[1], "rb"); 53 | if (!fd) 54 | { 55 | fprintf(stderr, "%s: can't open %s for reading\n", argv[0], argv[1]); 56 | return -1; 57 | } 58 | 59 | make_ident(argv[1]); 60 | size_t rd = 0; 61 | size_t totalsize = 0; 62 | printf("const unsigned char %s[] =\n{\n", filename); 63 | for (int total = 0, need_comma = 0; (rd = fread(buf, 1, BUFSIZ, fd)) > 0; ) 64 | { 65 | totalsize += rd; 66 | if (!rd) 67 | { 68 | fprintf(stderr, "%s: file read error\n", argv[0]); 69 | return -1; 70 | } 71 | for (size_t i = 0; i < rd; i++) 72 | { 73 | if (need_comma) printf(", "); 74 | else need_comma = 1; 75 | if ((total % 11) == 0) printf("\n\t"); 76 | printf("0x%.2x", buf[i]); 77 | total++; 78 | } 79 | } 80 | printf("\n};\n"); 81 | printf("const unsigned long long %s_len = %u;\n", filename, totalsize); 82 | return 0; 83 | } 84 | -------------------------------------------------------------------------------- /dll/UserManual-RUS.odt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pugnator/openvsm/c28a7a8210ea2fabc57951ce33cfb3b047d4348d/dll/UserManual-RUS.odt -------------------------------------------------------------------------------- /dll/UserManual-RUS.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pugnator/openvsm/c28a7a8210ea2fabc57951ce33cfb3b047d4348d/dll/UserManual-RUS.pdf -------------------------------------------------------------------------------- /dll/nand.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pugnator/openvsm/c28a7a8210ea2fabc57951ce33cfb3b047d4348d/dll/nand.gif -------------------------------------------------------------------------------- /examples/NAND/README.md: -------------------------------------------------------------------------------- 1 | Simple NAND demonstration board. Press the button to change LEDs' state -------------------------------------------------------------------------------- /examples/NAND/device.txt: -------------------------------------------------------------------------------- 1 | {*DEVICE} 2 | NAME=LUA_NAND 3 | 4 | {PREFIX=U} 5 | 6 | {*PROPDEFS} 7 | 8 | {MODDLL="VSM Model DLL",HIDDEN STRING} 9 | 10 | {LUA="LUA",STRING} 11 | 12 | {PRIMITIVE="Primitive Type",HIDDEN STRING} 13 | 14 | {PACKAGE="PCB Package",PACKAGE,0} 15 | 16 | {*INDEX} 17 | 18 | {CAT=Microprocessor ICs} 19 | 20 | {DESC=NAND Lus test model} 21 | 22 | {MFR=USSR} 23 | 24 | {SUBCAT=} 25 | 26 | {*COMPONENT} 27 | 28 | {PRIMITIVE=DIGITAL} 29 | 30 | {MODDLL=openvsm.DLL} 31 | { 32 | LUA=device.lua} 33 | 34 | {PACKAGE=DIL8} 35 | -------------------------------------------------------------------------------- /examples/NAND/nand.lua: -------------------------------------------------------------------------------- 1 | SAFE_MODE=true 2 | LOGIC_TYPE=TTL 3 | device_pins = 4 | { 5 | {name = "A", on_time=100000, off_time=100000}, 6 | {name = "B", on_time=100000, off_time=100000}, 7 | {name = "Q", on_time=100000, off_time=100000} 8 | } 9 | function device_simulate () 10 | Q:set(1-(A:get() * B:get())) 11 | end -------------------------------------------------------------------------------- /examples/NAND/nand.pdsprj: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pugnator/openvsm/c28a7a8210ea2fabc57951ce33cfb3b047d4348d/examples/NAND/nand.pdsprj -------------------------------------------------------------------------------- /externals/installer/README.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pugnator/openvsm/c28a7a8210ea2fabc57951ce33cfb3b047d4348d/externals/installer/README.md -------------------------------------------------------------------------------- /externals/installer/openvsm.iss: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pugnator/openvsm/c28a7a8210ea2fabc57951ce33cfb3b047d4348d/externals/installer/openvsm.iss -------------------------------------------------------------------------------- /externals/lua/README: -------------------------------------------------------------------------------- 1 | 2 | This is Lua 5.4.4, released on 13 Jan 2022. 3 | 4 | For installation instructions, license details, and 5 | further information about Lua, see doc/readme.html. 6 | 7 | -------------------------------------------------------------------------------- /externals/lua/doc/logo.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pugnator/openvsm/c28a7a8210ea2fabc57951ce33cfb3b047d4348d/externals/lua/doc/logo.gif -------------------------------------------------------------------------------- /externals/lua/doc/lua.1: -------------------------------------------------------------------------------- 1 | .\" $Id: lua.man,v 1.14 2020/05/21 19:31:21 lhf Exp $ 2 | .TH LUA 1 "$Date: 2020/05/21 19:31:21 $" 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 | After handling the 29 | .IR options , 30 | the Lua program in file 31 | .I script 32 | is loaded and executed. 33 | The 34 | .I args 35 | are available to 36 | .I script 37 | as strings in a global table named 38 | .B arg 39 | and also as arguments to its main function. 40 | When called without arguments, 41 | .B lua 42 | behaves as 43 | .B "lua \-v \-i" 44 | if the standard input is a terminal, 45 | and as 46 | .B "lua \-" 47 | otherwise. 48 | .LP 49 | In interactive mode, 50 | .B lua 51 | prompts the user, 52 | reads lines from the standard input, 53 | and executes them as they are read. 54 | If the line contains an expression, 55 | then the line is evaluated and the result is printed. 56 | If a line does not contain a complete statement, 57 | then a secondary prompt is displayed and 58 | lines are read until a complete statement is formed or 59 | a syntax error is found. 60 | .LP 61 | Before handling command line options and scripts, 62 | .B lua 63 | checks the contents of the environment variables 64 | .B LUA_INIT_5_4 65 | and 66 | .BR LUA_INIT , 67 | in that order. 68 | If the contents are of the form 69 | .RI '@ filename ', 70 | then 71 | .I filename 72 | is executed. 73 | Otherwise, the contents are assumed to be a Lua statement and is executed. 74 | When 75 | .B LUA_INIT_5_4 76 | is defined, 77 | .B LUA_INIT 78 | is ignored. 79 | .SH OPTIONS 80 | .TP 81 | .BI \-e " stat" 82 | execute statement 83 | .IR stat . 84 | .TP 85 | .B \-i 86 | enter interactive mode after executing 87 | .IR script . 88 | .TP 89 | .BI \-l " name" 90 | require library 91 | .I name 92 | into global 93 | .IR name . 94 | .TP 95 | .B \-v 96 | show version information. 97 | .TP 98 | .B \-E 99 | ignore environment variables. 100 | .TP 101 | .B \-W 102 | turn warnings on. 103 | .TP 104 | .B \-\- 105 | stop handling options. 106 | .TP 107 | .B \- 108 | stop handling options and execute the standard input as a file. 109 | .SH ENVIRONMENT VARIABLES 110 | The following environment variables affect the execution of 111 | .BR lua . 112 | When defined, 113 | the version-specific variants take priority 114 | and the version-neutral variants are ignored. 115 | .TP 116 | .B LUA_INIT, LUA_INIT_5_4 117 | Code to be executed before command line options and scripts. 118 | .TP 119 | .B LUA_PATH, LUA_PATH_5_4 120 | Initial value of package.cpath, 121 | the path used by require to search for Lua loaders. 122 | .TP 123 | .B LUA_CPATH, LUA_CPATH_5_4 124 | Initial value of package.cpath, 125 | the path used by require to search for C loaders. 126 | .SH EXIT STATUS 127 | If a script calls os.exit, 128 | then 129 | .B lua 130 | exits with the given exit status. 131 | Otherwise, 132 | .B lua 133 | exits 134 | with EXIT_SUCCESS (0 on POSIX systems) if there were no errors 135 | and 136 | with EXIT_FAILURE (1 on POSIX systems) if there were errors. 137 | Errors raised in interactive mode do not cause exits. 138 | .SH DIAGNOSTICS 139 | Error messages should be self explanatory. 140 | .SH "SEE ALSO" 141 | .BR luac (1) 142 | .br 143 | The documentation at lua.org, 144 | especially section 7 of the reference manual. 145 | .SH AUTHORS 146 | R. Ierusalimschy, 147 | L. H. de Figueiredo, 148 | W. Celes 149 | .\" EOF 150 | -------------------------------------------------------------------------------- /externals/lua/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 | -------------------------------------------------------------------------------- /externals/lua/doc/osi-certified-72x60.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pugnator/openvsm/c28a7a8210ea2fabc57951ce33cfb3b047d4348d/externals/lua/doc/osi-certified-72x60.png -------------------------------------------------------------------------------- /externals/lua/src/Makefile: -------------------------------------------------------------------------------- 1 | # Makefile for building 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= guess 8 | 9 | CC= i686-w64-mingw32-cc -std=gnu99 10 | CFLAGS= -O2 -Wall -Wextra -DLUA_COMPAT_5_3 $(SYSCFLAGS) $(MYCFLAGS) 11 | LDFLAGS= $(SYSLDFLAGS) $(MYLDFLAGS) 12 | LIBS= -lm $(SYSLIBS) $(MYLIBS) 13 | 14 | AR= ar rcu 15 | RANLIB= ranlib 16 | RM= rm -f 17 | UNAME= uname 18 | 19 | SYSCFLAGS= 20 | SYSLDFLAGS= 21 | SYSLIBS= 22 | 23 | MYCFLAGS= 24 | MYLDFLAGS= 25 | MYLIBS= 26 | MYOBJS= 27 | 28 | # Special flags for compiler modules; -Os reduces code size. 29 | CMCFLAGS= 30 | 31 | # == END OF USER SETTINGS -- NO NEED TO CHANGE ANYTHING BELOW THIS LINE ======= 32 | 33 | PLATS= guess aix bsd c89 freebsd generic linux linux-readline macosx mingw posix solaris 34 | 35 | LUA_A= liblua.a 36 | CORE_O= lapi.o lcode.o lctype.o ldebug.o ldo.o ldump.o lfunc.o lgc.o llex.o lmem.o lobject.o lopcodes.o lparser.o lstate.o lstring.o ltable.o ltm.o lundump.o lvm.o lzio.o 37 | LIB_O= lauxlib.o lbaselib.o lcorolib.o ldblib.o liolib.o lmathlib.o loadlib.o loslib.o lstrlib.o ltablib.o lutf8lib.o linit.o 38 | BASE_O= $(CORE_O) $(LIB_O) $(MYOBJS) 39 | 40 | LUA_T= lua 41 | LUA_O= lua.o 42 | 43 | LUAC_T= luac 44 | LUAC_O= luac.o 45 | 46 | ALL_O= $(BASE_O) $(LUA_O) $(LUAC_O) 47 | ALL_T= $(LUA_A) $(LUA_T) $(LUAC_T) 48 | ALL_A= $(LUA_A) 49 | 50 | # Targets start here. 51 | default: $(PLAT) 52 | 53 | all: $(ALL_T) 54 | 55 | o: $(ALL_O) 56 | 57 | a: $(ALL_A) 58 | 59 | $(LUA_A): $(BASE_O) 60 | $(AR) $@ $(BASE_O) 61 | $(RANLIB) $@ 62 | 63 | $(LUA_T): $(LUA_O) $(LUA_A) 64 | $(CC) -o $@ $(LDFLAGS) $(LUA_O) $(LUA_A) $(LIBS) 65 | 66 | $(LUAC_T): $(LUAC_O) $(LUA_A) 67 | $(CC) -o $@ $(LDFLAGS) $(LUAC_O) $(LUA_A) $(LIBS) 68 | 69 | test: 70 | ./$(LUA_T) -v 71 | 72 | clean: 73 | $(RM) $(ALL_T) $(ALL_O) 74 | 75 | depend: 76 | @$(CC) $(CFLAGS) -MM l*.c 77 | 78 | echo: 79 | @echo "PLAT= $(PLAT)" 80 | @echo "CC= $(CC)" 81 | @echo "CFLAGS= $(CFLAGS)" 82 | @echo "LDFLAGS= $(LDFLAGS)" 83 | @echo "LIBS= $(LIBS)" 84 | @echo "AR= $(AR)" 85 | @echo "RANLIB= $(RANLIB)" 86 | @echo "RM= $(RM)" 87 | @echo "UNAME= $(UNAME)" 88 | 89 | # Convenience targets for popular platforms. 90 | ALL= all 91 | 92 | help: 93 | @echo "Do 'make PLATFORM' where PLATFORM is one of these:" 94 | @echo " $(PLATS)" 95 | @echo "See doc/readme.html for complete instructions." 96 | 97 | guess: 98 | @echo Guessing `$(UNAME)` 99 | @$(MAKE) `$(UNAME)` 100 | 101 | AIX aix: 102 | $(MAKE) $(ALL) CC="xlc" CFLAGS="-O2 -DLUA_USE_POSIX -DLUA_USE_DLOPEN" SYSLIBS="-ldl" SYSLDFLAGS="-brtl -bexpall" 103 | 104 | bsd: 105 | $(MAKE) $(ALL) SYSCFLAGS="-DLUA_USE_POSIX -DLUA_USE_DLOPEN" SYSLIBS="-Wl,-E" 106 | 107 | c89: 108 | $(MAKE) $(ALL) SYSCFLAGS="-DLUA_USE_C89" CC="gcc -std=c89" 109 | @echo '' 110 | @echo '*** C89 does not guarantee 64-bit integers for Lua.' 111 | @echo '*** Make sure to compile all external Lua libraries' 112 | @echo '*** with LUA_USE_C89 to ensure consistency' 113 | @echo '' 114 | 115 | FreeBSD NetBSD OpenBSD freebsd: 116 | $(MAKE) $(ALL) SYSCFLAGS="-DLUA_USE_LINUX -DLUA_USE_READLINE -I/usr/include/edit" SYSLIBS="-Wl,-E -ledit" CC="cc" 117 | 118 | generic: $(ALL) 119 | 120 | Linux linux: linux-noreadline 121 | 122 | linux-noreadline: 123 | $(MAKE) $(ALL) SYSCFLAGS="-DLUA_USE_LINUX" SYSLIBS="-Wl,-E -ldl" 124 | 125 | linux-readline: 126 | $(MAKE) $(ALL) SYSCFLAGS="-DLUA_USE_LINUX -DLUA_USE_READLINE" SYSLIBS="-Wl,-E -ldl -lreadline" 127 | 128 | Darwin macos macosx: 129 | $(MAKE) $(ALL) SYSCFLAGS="-DLUA_USE_MACOSX -DLUA_USE_READLINE" SYSLIBS="-lreadline" 130 | 131 | mingw: 132 | $(MAKE) "LUA_A=lua54.dll" "LUA_T=lua.exe" \ 133 | "AR=$(CC) -shared -o" "RANLIB=strip --strip-unneeded" \ 134 | "SYSCFLAGS=-DLUA_BUILD_AS_DLL" "SYSLIBS=" "SYSLDFLAGS=-s" lua.exe 135 | $(MAKE) "LUAC_T=luac.exe" luac.exe 136 | 137 | posix: 138 | $(MAKE) $(ALL) SYSCFLAGS="-DLUA_USE_POSIX" 139 | 140 | SunOS solaris: 141 | $(MAKE) $(ALL) SYSCFLAGS="-DLUA_USE_POSIX -DLUA_USE_DLOPEN -D_REENTRANT" SYSLIBS="-ldl" 142 | 143 | # Targets that do not create files (not all makes understand .PHONY). 144 | .PHONY: all $(PLATS) help test clean default o a depend echo 145 | 146 | # Compiler modules may use special flags. 147 | llex.o: 148 | $(CC) $(CFLAGS) $(CMCFLAGS) -c llex.c 149 | 150 | lparser.o: 151 | $(CC) $(CFLAGS) $(CMCFLAGS) -c lparser.c 152 | 153 | lcode.o: 154 | $(CC) $(CFLAGS) $(CMCFLAGS) -c lcode.c 155 | 156 | # DO NOT DELETE 157 | 158 | lapi.o: lapi.c lprefix.h lua.h luaconf.h lapi.h llimits.h lstate.h \ 159 | lobject.h ltm.h lzio.h lmem.h ldebug.h ldo.h lfunc.h lgc.h lstring.h \ 160 | ltable.h lundump.h lvm.h 161 | lauxlib.o: lauxlib.c lprefix.h lua.h luaconf.h lauxlib.h 162 | lbaselib.o: lbaselib.c lprefix.h lua.h luaconf.h lauxlib.h lualib.h 163 | lcode.o: lcode.c lprefix.h lua.h luaconf.h lcode.h llex.h lobject.h \ 164 | llimits.h lzio.h lmem.h lopcodes.h lparser.h ldebug.h lstate.h ltm.h \ 165 | ldo.h lgc.h lstring.h ltable.h lvm.h 166 | lcorolib.o: lcorolib.c lprefix.h lua.h luaconf.h lauxlib.h lualib.h 167 | lctype.o: lctype.c lprefix.h lctype.h lua.h luaconf.h llimits.h 168 | ldblib.o: ldblib.c lprefix.h lua.h luaconf.h lauxlib.h lualib.h 169 | ldebug.o: ldebug.c lprefix.h lua.h luaconf.h lapi.h llimits.h lstate.h \ 170 | lobject.h ltm.h lzio.h lmem.h lcode.h llex.h lopcodes.h lparser.h \ 171 | ldebug.h ldo.h lfunc.h lstring.h lgc.h ltable.h lvm.h 172 | ldo.o: ldo.c lprefix.h lua.h luaconf.h lapi.h llimits.h lstate.h \ 173 | lobject.h ltm.h lzio.h lmem.h ldebug.h ldo.h lfunc.h lgc.h lopcodes.h \ 174 | lparser.h lstring.h ltable.h lundump.h lvm.h 175 | ldump.o: ldump.c lprefix.h lua.h luaconf.h lobject.h llimits.h lstate.h \ 176 | ltm.h lzio.h lmem.h lundump.h 177 | lfunc.o: lfunc.c lprefix.h lua.h luaconf.h ldebug.h lstate.h lobject.h \ 178 | llimits.h ltm.h lzio.h lmem.h ldo.h lfunc.h lgc.h 179 | lgc.o: lgc.c lprefix.h lua.h luaconf.h ldebug.h lstate.h lobject.h \ 180 | llimits.h ltm.h lzio.h lmem.h ldo.h lfunc.h lgc.h lstring.h ltable.h 181 | linit.o: linit.c lprefix.h lua.h luaconf.h lualib.h lauxlib.h 182 | liolib.o: liolib.c lprefix.h lua.h luaconf.h lauxlib.h lualib.h 183 | llex.o: llex.c lprefix.h lua.h luaconf.h lctype.h llimits.h ldebug.h \ 184 | lstate.h lobject.h ltm.h lzio.h lmem.h ldo.h lgc.h llex.h lparser.h \ 185 | lstring.h ltable.h 186 | lmathlib.o: lmathlib.c lprefix.h lua.h luaconf.h lauxlib.h lualib.h 187 | lmem.o: lmem.c lprefix.h lua.h luaconf.h ldebug.h lstate.h lobject.h \ 188 | llimits.h ltm.h lzio.h lmem.h ldo.h lgc.h 189 | loadlib.o: loadlib.c lprefix.h lua.h luaconf.h lauxlib.h lualib.h 190 | lobject.o: lobject.c lprefix.h lua.h luaconf.h lctype.h llimits.h \ 191 | ldebug.h lstate.h lobject.h ltm.h lzio.h lmem.h ldo.h lstring.h lgc.h \ 192 | lvm.h 193 | lopcodes.o: lopcodes.c lprefix.h lopcodes.h llimits.h lua.h luaconf.h 194 | loslib.o: loslib.c lprefix.h lua.h luaconf.h lauxlib.h lualib.h 195 | lparser.o: lparser.c lprefix.h lua.h luaconf.h lcode.h llex.h lobject.h \ 196 | llimits.h lzio.h lmem.h lopcodes.h lparser.h ldebug.h lstate.h ltm.h \ 197 | ldo.h lfunc.h lstring.h lgc.h ltable.h 198 | lstate.o: lstate.c lprefix.h lua.h luaconf.h lapi.h llimits.h lstate.h \ 199 | lobject.h ltm.h lzio.h lmem.h ldebug.h ldo.h lfunc.h lgc.h llex.h \ 200 | lstring.h ltable.h 201 | lstring.o: lstring.c lprefix.h lua.h luaconf.h ldebug.h lstate.h \ 202 | lobject.h llimits.h ltm.h lzio.h lmem.h ldo.h lstring.h lgc.h 203 | lstrlib.o: lstrlib.c lprefix.h lua.h luaconf.h lauxlib.h lualib.h 204 | ltable.o: ltable.c lprefix.h lua.h luaconf.h ldebug.h lstate.h lobject.h \ 205 | llimits.h ltm.h lzio.h lmem.h ldo.h lgc.h lstring.h ltable.h lvm.h 206 | ltablib.o: ltablib.c lprefix.h lua.h luaconf.h lauxlib.h lualib.h 207 | ltm.o: ltm.c lprefix.h lua.h luaconf.h ldebug.h lstate.h lobject.h \ 208 | llimits.h ltm.h lzio.h lmem.h ldo.h lgc.h lstring.h ltable.h lvm.h 209 | lua.o: lua.c lprefix.h lua.h luaconf.h lauxlib.h lualib.h 210 | luac.o: luac.c lprefix.h lua.h luaconf.h lauxlib.h ldebug.h lstate.h \ 211 | lobject.h llimits.h ltm.h lzio.h lmem.h lopcodes.h lopnames.h lundump.h 212 | lundump.o: lundump.c lprefix.h lua.h luaconf.h ldebug.h lstate.h \ 213 | lobject.h llimits.h ltm.h lzio.h lmem.h ldo.h lfunc.h lstring.h lgc.h \ 214 | lundump.h 215 | lutf8lib.o: lutf8lib.c lprefix.h lua.h luaconf.h lauxlib.h lualib.h 216 | lvm.o: lvm.c lprefix.h lua.h luaconf.h ldebug.h lstate.h lobject.h \ 217 | llimits.h ltm.h lzio.h lmem.h ldo.h lfunc.h lgc.h lopcodes.h lstring.h \ 218 | ltable.h lvm.h ljumptab.h 219 | lzio.o: lzio.c lprefix.h lua.h luaconf.h llimits.h lmem.h lstate.h \ 220 | lobject.h ltm.h lzio.h 221 | 222 | # (end of Makefile) 223 | -------------------------------------------------------------------------------- /externals/lua/src/lapi.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lapi.h $ 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 | 15 | /* Increments 'L->top', checking for stack overflows */ 16 | #define api_incr_top(L) {L->top++; api_check(L, L->top <= L->ci->top, \ 17 | "stack overflow");} 18 | 19 | 20 | /* 21 | ** If a call returns too many multiple returns, the callee may not have 22 | ** stack space to accommodate all results. In this case, this macro 23 | ** increases its stack space ('L->ci->top'). 24 | */ 25 | #define adjustresults(L,nres) \ 26 | { if ((nres) <= LUA_MULTRET && L->ci->top < L->top) L->ci->top = L->top; } 27 | 28 | 29 | /* Ensure the stack has at least 'n' elements */ 30 | #define api_checknelems(L,n) api_check(L, (n) < (L->top - L->ci->func), \ 31 | "not enough elements in the stack") 32 | 33 | 34 | /* 35 | ** To reduce the overhead of returning from C functions, the presence of 36 | ** to-be-closed variables in these functions is coded in the CallInfo's 37 | ** field 'nresults', in a way that functions with no to-be-closed variables 38 | ** with zero, one, or "all" wanted results have no overhead. Functions 39 | ** with other number of wanted results, as well as functions with 40 | ** variables to be closed, have an extra check. 41 | */ 42 | 43 | #define hastocloseCfunc(n) ((n) < LUA_MULTRET) 44 | 45 | /* Map [-1, inf) (range of 'nresults') into (-inf, -2] */ 46 | #define codeNresults(n) (-(n) - 3) 47 | #define decodeNresults(n) (-(n) - 3) 48 | 49 | #endif 50 | -------------------------------------------------------------------------------- /externals/lua/src/lcode.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lcode.h $ 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 | /* arithmetic operators */ 28 | OPR_ADD, OPR_SUB, OPR_MUL, OPR_MOD, OPR_POW, 29 | OPR_DIV, OPR_IDIV, 30 | /* bitwise operators */ 31 | OPR_BAND, OPR_BOR, OPR_BXOR, 32 | OPR_SHL, OPR_SHR, 33 | /* string operator */ 34 | OPR_CONCAT, 35 | /* comparison operators */ 36 | OPR_EQ, OPR_LT, OPR_LE, 37 | OPR_NE, OPR_GT, OPR_GE, 38 | /* logical operators */ 39 | OPR_AND, OPR_OR, 40 | OPR_NOBINOPR 41 | } BinOpr; 42 | 43 | 44 | /* true if operation is foldable (that is, it is arithmetic or bitwise) */ 45 | #define foldbinop(op) ((op) <= OPR_SHR) 46 | 47 | 48 | #define luaK_codeABC(fs,o,a,b,c) luaK_codeABCk(fs,o,a,b,c,0) 49 | 50 | 51 | typedef enum UnOpr { OPR_MINUS, OPR_BNOT, OPR_NOT, OPR_LEN, OPR_NOUNOPR } UnOpr; 52 | 53 | 54 | /* get (pointer to) instruction of given 'expdesc' */ 55 | #define getinstruction(fs,e) ((fs)->f->code[(e)->u.info]) 56 | 57 | 58 | #define luaK_setmultret(fs,e) luaK_setreturns(fs, e, LUA_MULTRET) 59 | 60 | #define luaK_jumpto(fs,t) luaK_patchlist(fs, luaK_jump(fs), t) 61 | 62 | LUAI_FUNC int luaK_code (FuncState *fs, Instruction i); 63 | LUAI_FUNC int luaK_codeABx (FuncState *fs, OpCode o, int A, unsigned int Bx); 64 | LUAI_FUNC int luaK_codeAsBx (FuncState *fs, OpCode o, int A, int Bx); 65 | LUAI_FUNC int luaK_codeABCk (FuncState *fs, OpCode o, int A, 66 | int B, int C, int k); 67 | LUAI_FUNC int luaK_isKint (expdesc *e); 68 | LUAI_FUNC int luaK_exp2const (FuncState *fs, const expdesc *e, TValue *v); 69 | LUAI_FUNC void luaK_fixline (FuncState *fs, int line); 70 | LUAI_FUNC void luaK_nil (FuncState *fs, int from, int n); 71 | LUAI_FUNC void luaK_reserveregs (FuncState *fs, int n); 72 | LUAI_FUNC void luaK_checkstack (FuncState *fs, int n); 73 | LUAI_FUNC void luaK_int (FuncState *fs, int reg, lua_Integer n); 74 | LUAI_FUNC void luaK_dischargevars (FuncState *fs, expdesc *e); 75 | LUAI_FUNC int luaK_exp2anyreg (FuncState *fs, expdesc *e); 76 | LUAI_FUNC void luaK_exp2anyregup (FuncState *fs, expdesc *e); 77 | LUAI_FUNC void luaK_exp2nextreg (FuncState *fs, expdesc *e); 78 | LUAI_FUNC void luaK_exp2val (FuncState *fs, expdesc *e); 79 | LUAI_FUNC int luaK_exp2RK (FuncState *fs, expdesc *e); 80 | LUAI_FUNC void luaK_self (FuncState *fs, expdesc *e, expdesc *key); 81 | LUAI_FUNC void luaK_indexed (FuncState *fs, expdesc *t, expdesc *k); 82 | LUAI_FUNC void luaK_goiftrue (FuncState *fs, expdesc *e); 83 | LUAI_FUNC void luaK_goiffalse (FuncState *fs, expdesc *e); 84 | LUAI_FUNC void luaK_storevar (FuncState *fs, expdesc *var, expdesc *e); 85 | LUAI_FUNC void luaK_setreturns (FuncState *fs, expdesc *e, int nresults); 86 | LUAI_FUNC void luaK_setoneret (FuncState *fs, expdesc *e); 87 | LUAI_FUNC int luaK_jump (FuncState *fs); 88 | LUAI_FUNC void luaK_ret (FuncState *fs, int first, int nret); 89 | LUAI_FUNC void luaK_patchlist (FuncState *fs, int list, int target); 90 | LUAI_FUNC void luaK_patchtohere (FuncState *fs, int list); 91 | LUAI_FUNC void luaK_concat (FuncState *fs, int *l1, int l2); 92 | LUAI_FUNC int luaK_getlabel (FuncState *fs); 93 | LUAI_FUNC void luaK_prefix (FuncState *fs, UnOpr op, expdesc *v, int line); 94 | LUAI_FUNC void luaK_infix (FuncState *fs, BinOpr op, expdesc *v); 95 | LUAI_FUNC void luaK_posfix (FuncState *fs, BinOpr op, expdesc *v1, 96 | expdesc *v2, int line); 97 | LUAI_FUNC void luaK_settablesize (FuncState *fs, int pc, 98 | int ra, int asize, int hsize); 99 | LUAI_FUNC void luaK_setlist (FuncState *fs, int base, int nelems, int tostore); 100 | LUAI_FUNC void luaK_finish (FuncState *fs); 101 | LUAI_FUNC l_noret luaK_semerror (LexState *ls, const char *msg); 102 | 103 | 104 | #endif 105 | -------------------------------------------------------------------------------- /externals/lua/src/lcorolib.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lcorolib.c $ 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_argexpected(L, co, 1, "thread"); 24 | return co; 25 | } 26 | 27 | 28 | /* 29 | ** Resumes a coroutine. Returns the number of results for non-error 30 | ** cases or -1 for errors. 31 | */ 32 | static int auxresume (lua_State *L, lua_State *co, int narg) { 33 | int status, nres; 34 | if (l_unlikely(!lua_checkstack(co, narg))) { 35 | lua_pushliteral(L, "too many arguments to resume"); 36 | return -1; /* error flag */ 37 | } 38 | lua_xmove(L, co, narg); 39 | status = lua_resume(co, L, narg, &nres); 40 | if (l_likely(status == LUA_OK || status == LUA_YIELD)) { 41 | if (l_unlikely(!lua_checkstack(L, nres + 1))) { 42 | lua_pop(co, nres); /* remove results anyway */ 43 | lua_pushliteral(L, "too many results to resume"); 44 | return -1; /* error flag */ 45 | } 46 | lua_xmove(co, L, nres); /* move yielded values */ 47 | return nres; 48 | } 49 | else { 50 | lua_xmove(co, L, 1); /* move error message */ 51 | return -1; /* error flag */ 52 | } 53 | } 54 | 55 | 56 | static int luaB_coresume (lua_State *L) { 57 | lua_State *co = getco(L); 58 | int r; 59 | r = auxresume(L, co, lua_gettop(L) - 1); 60 | if (l_unlikely(r < 0)) { 61 | lua_pushboolean(L, 0); 62 | lua_insert(L, -2); 63 | return 2; /* return false + error message */ 64 | } 65 | else { 66 | lua_pushboolean(L, 1); 67 | lua_insert(L, -(r + 1)); 68 | return r + 1; /* return true + 'resume' returns */ 69 | } 70 | } 71 | 72 | 73 | static int luaB_auxwrap (lua_State *L) { 74 | lua_State *co = lua_tothread(L, lua_upvalueindex(1)); 75 | int r = auxresume(L, co, lua_gettop(L)); 76 | if (l_unlikely(r < 0)) { /* error? */ 77 | int stat = lua_status(co); 78 | if (stat != LUA_OK && stat != LUA_YIELD) { /* error in the coroutine? */ 79 | stat = lua_resetthread(co); /* close its tbc variables */ 80 | lua_assert(stat != LUA_OK); 81 | lua_xmove(co, L, 1); /* move error message to the caller */ 82 | } 83 | if (stat != LUA_ERRMEM && /* not a memory error and ... */ 84 | lua_type(L, -1) == LUA_TSTRING) { /* ... error object is a string? */ 85 | luaL_where(L, 1); /* add extra info, if available */ 86 | lua_insert(L, -2); 87 | lua_concat(L, 2); 88 | } 89 | return lua_error(L); /* propagate error */ 90 | } 91 | return r; 92 | } 93 | 94 | 95 | static int luaB_cocreate (lua_State *L) { 96 | lua_State *NL; 97 | luaL_checktype(L, 1, LUA_TFUNCTION); 98 | NL = lua_newthread(L); 99 | lua_pushvalue(L, 1); /* move function to top */ 100 | lua_xmove(L, NL, 1); /* move function from L to NL */ 101 | return 1; 102 | } 103 | 104 | 105 | static int luaB_cowrap (lua_State *L) { 106 | luaB_cocreate(L); 107 | lua_pushcclosure(L, luaB_auxwrap, 1); 108 | return 1; 109 | } 110 | 111 | 112 | static int luaB_yield (lua_State *L) { 113 | return lua_yield(L, lua_gettop(L)); 114 | } 115 | 116 | 117 | #define COS_RUN 0 118 | #define COS_DEAD 1 119 | #define COS_YIELD 2 120 | #define COS_NORM 3 121 | 122 | 123 | static const char *const statname[] = 124 | {"running", "dead", "suspended", "normal"}; 125 | 126 | 127 | static int auxstatus (lua_State *L, lua_State *co) { 128 | if (L == co) return COS_RUN; 129 | else { 130 | switch (lua_status(co)) { 131 | case LUA_YIELD: 132 | return COS_YIELD; 133 | case LUA_OK: { 134 | lua_Debug ar; 135 | if (lua_getstack(co, 0, &ar)) /* does it have frames? */ 136 | return COS_NORM; /* it is running */ 137 | else if (lua_gettop(co) == 0) 138 | return COS_DEAD; 139 | else 140 | return COS_YIELD; /* initial state */ 141 | } 142 | default: /* some error occurred */ 143 | return COS_DEAD; 144 | } 145 | } 146 | } 147 | 148 | 149 | static int luaB_costatus (lua_State *L) { 150 | lua_State *co = getco(L); 151 | lua_pushstring(L, statname[auxstatus(L, co)]); 152 | return 1; 153 | } 154 | 155 | 156 | static int luaB_yieldable (lua_State *L) { 157 | lua_State *co = lua_isnone(L, 1) ? L : getco(L); 158 | lua_pushboolean(L, lua_isyieldable(co)); 159 | return 1; 160 | } 161 | 162 | 163 | static int luaB_corunning (lua_State *L) { 164 | int ismain = lua_pushthread(L); 165 | lua_pushboolean(L, ismain); 166 | return 2; 167 | } 168 | 169 | 170 | static int luaB_close (lua_State *L) { 171 | lua_State *co = getco(L); 172 | int status = auxstatus(L, co); 173 | switch (status) { 174 | case COS_DEAD: case COS_YIELD: { 175 | status = lua_resetthread(co); 176 | if (status == LUA_OK) { 177 | lua_pushboolean(L, 1); 178 | return 1; 179 | } 180 | else { 181 | lua_pushboolean(L, 0); 182 | lua_xmove(co, L, 1); /* move error message */ 183 | return 2; 184 | } 185 | } 186 | default: /* normal or running coroutine */ 187 | return luaL_error(L, "cannot close a %s coroutine", statname[status]); 188 | } 189 | } 190 | 191 | 192 | static const luaL_Reg co_funcs[] = { 193 | {"create", luaB_cocreate}, 194 | {"resume", luaB_coresume}, 195 | {"running", luaB_corunning}, 196 | {"status", luaB_costatus}, 197 | {"wrap", luaB_cowrap}, 198 | {"yield", luaB_yield}, 199 | {"isyieldable", luaB_yieldable}, 200 | {"close", luaB_close}, 201 | {NULL, NULL} 202 | }; 203 | 204 | 205 | 206 | LUAMOD_API int luaopen_coroutine (lua_State *L) { 207 | luaL_newlib(L, co_funcs); 208 | return 1; 209 | } 210 | 211 | -------------------------------------------------------------------------------- /externals/lua/src/lctype.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lctype.c $ 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 | 20 | #if defined (LUA_UCID) /* accept UniCode IDentifiers? */ 21 | /* consider all non-ascii codepoints to be alphabetic */ 22 | #define NONA 0x01 23 | #else 24 | #define NONA 0x00 /* default */ 25 | #endif 26 | 27 | 28 | LUAI_DDEF const lu_byte luai_ctype_[UCHAR_MAX + 2] = { 29 | 0x00, /* EOZ */ 30 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0. */ 31 | 0x00, 0x08, 0x08, 0x08, 0x08, 0x08, 0x00, 0x00, 32 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 1. */ 33 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 34 | 0x0c, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, /* 2. */ 35 | 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 36 | 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, /* 3. */ 37 | 0x16, 0x16, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 38 | 0x04, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x05, /* 4. */ 39 | 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 40 | 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, /* 5. */ 41 | 0x05, 0x05, 0x05, 0x04, 0x04, 0x04, 0x04, 0x05, 42 | 0x04, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x05, /* 6. */ 43 | 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 44 | 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, /* 7. */ 45 | 0x05, 0x05, 0x05, 0x04, 0x04, 0x04, 0x04, 0x00, 46 | NONA, NONA, NONA, NONA, NONA, NONA, NONA, NONA, /* 8. */ 47 | NONA, NONA, NONA, NONA, NONA, NONA, NONA, NONA, 48 | NONA, NONA, NONA, NONA, NONA, NONA, NONA, NONA, /* 9. */ 49 | NONA, NONA, NONA, NONA, NONA, NONA, NONA, NONA, 50 | NONA, NONA, NONA, NONA, NONA, NONA, NONA, NONA, /* a. */ 51 | NONA, NONA, NONA, NONA, NONA, NONA, NONA, NONA, 52 | NONA, NONA, NONA, NONA, NONA, NONA, NONA, NONA, /* b. */ 53 | NONA, NONA, NONA, NONA, NONA, NONA, NONA, NONA, 54 | 0x00, 0x00, NONA, NONA, NONA, NONA, NONA, NONA, /* c. */ 55 | NONA, NONA, NONA, NONA, NONA, NONA, NONA, NONA, 56 | NONA, NONA, NONA, NONA, NONA, NONA, NONA, NONA, /* d. */ 57 | NONA, NONA, NONA, NONA, NONA, NONA, NONA, NONA, 58 | NONA, NONA, NONA, NONA, NONA, NONA, NONA, NONA, /* e. */ 59 | NONA, NONA, NONA, NONA, NONA, NONA, NONA, NONA, 60 | NONA, NONA, NONA, NONA, NONA, 0x00, 0x00, 0x00, /* f. */ 61 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 62 | }; 63 | 64 | #endif /* } */ 65 | -------------------------------------------------------------------------------- /externals/lua/src/lctype.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lctype.h $ 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 | /* 66 | ** In ASCII, this 'ltolower' is correct for alphabetic characters and 67 | ** for '.'. That is enough for Lua needs. ('check_exp' ensures that 68 | ** the character either is an upper-case letter or is unchanged by 69 | ** the transformation, which holds for lower-case letters and '.'.) 70 | */ 71 | #define ltolower(c) \ 72 | check_exp(('A' <= (c) && (c) <= 'Z') || (c) == ((c) | ('A' ^ 'a')), \ 73 | (c) | ('A' ^ 'a')) 74 | 75 | 76 | /* one entry for each character and for -1 (EOZ) */ 77 | LUAI_DDEC(const lu_byte luai_ctype_[UCHAR_MAX + 2];) 78 | 79 | 80 | #else /* }{ */ 81 | 82 | /* 83 | ** use standard C ctypes 84 | */ 85 | 86 | #include 87 | 88 | 89 | #define lislalpha(c) (isalpha(c) || (c) == '_') 90 | #define lislalnum(c) (isalnum(c) || (c) == '_') 91 | #define lisdigit(c) (isdigit(c)) 92 | #define lisspace(c) (isspace(c)) 93 | #define lisprint(c) (isprint(c)) 94 | #define lisxdigit(c) (isxdigit(c)) 95 | 96 | #define ltolower(c) (tolower(c)) 97 | 98 | #endif /* } */ 99 | 100 | #endif 101 | 102 | -------------------------------------------------------------------------------- /externals/lua/src/ldebug.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: ldebug.h $ 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 | 17 | /* Active Lua function (given call info) */ 18 | #define ci_func(ci) (clLvalue(s2v((ci)->func))) 19 | 20 | 21 | #define resethookcount(L) (L->hookcount = L->basehookcount) 22 | 23 | /* 24 | ** mark for entries in 'lineinfo' array that has absolute information in 25 | ** 'abslineinfo' array 26 | */ 27 | #define ABSLINEINFO (-0x80) 28 | 29 | 30 | /* 31 | ** MAXimum number of successive Instructions WiTHout ABSolute line 32 | ** information. (A power of two allows fast divisions.) 33 | */ 34 | #if !defined(MAXIWTHABS) 35 | #define MAXIWTHABS 128 36 | #endif 37 | 38 | 39 | LUAI_FUNC int luaG_getfuncline (const Proto *f, int pc); 40 | LUAI_FUNC const char *luaG_findlocal (lua_State *L, CallInfo *ci, int n, 41 | StkId *pos); 42 | LUAI_FUNC l_noret luaG_typeerror (lua_State *L, const TValue *o, 43 | const char *opname); 44 | LUAI_FUNC l_noret luaG_callerror (lua_State *L, const TValue *o); 45 | LUAI_FUNC l_noret luaG_forerror (lua_State *L, const TValue *o, 46 | const char *what); 47 | LUAI_FUNC l_noret luaG_concaterror (lua_State *L, const TValue *p1, 48 | const TValue *p2); 49 | LUAI_FUNC l_noret luaG_opinterror (lua_State *L, const TValue *p1, 50 | const TValue *p2, 51 | const char *msg); 52 | LUAI_FUNC l_noret luaG_tointerror (lua_State *L, const TValue *p1, 53 | const TValue *p2); 54 | LUAI_FUNC l_noret luaG_ordererror (lua_State *L, const TValue *p1, 55 | const TValue *p2); 56 | LUAI_FUNC l_noret luaG_runerror (lua_State *L, const char *fmt, ...); 57 | LUAI_FUNC const char *luaG_addinfo (lua_State *L, const char *msg, 58 | TString *src, int line); 59 | LUAI_FUNC l_noret luaG_errormsg (lua_State *L); 60 | LUAI_FUNC int luaG_traceexec (lua_State *L, const Instruction *pc); 61 | 62 | 63 | #endif 64 | -------------------------------------------------------------------------------- /externals/lua/src/ldo.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: ldo.h $ 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 | ** It also allows the running of one GC step when the stack is 21 | ** reallocated. 22 | ** 'condmovestack' is used in heavy tests to force a stack reallocation 23 | ** at every check. 24 | */ 25 | #define luaD_checkstackaux(L,n,pre,pos) \ 26 | if (l_unlikely(L->stack_last - L->top <= (n))) \ 27 | { pre; luaD_growstack(L, n, 1); pos; } \ 28 | else { condmovestack(L,pre,pos); } 29 | 30 | /* In general, 'pre'/'pos' are empty (nothing to save) */ 31 | #define luaD_checkstack(L,n) luaD_checkstackaux(L,n,(void)0,(void)0) 32 | 33 | 34 | 35 | #define savestack(L,p) ((char *)(p) - (char *)L->stack) 36 | #define restorestack(L,n) ((StkId)((char *)L->stack + (n))) 37 | 38 | 39 | /* macro to check stack size, preserving 'p' */ 40 | #define checkstackGCp(L,n,p) \ 41 | luaD_checkstackaux(L, n, \ 42 | ptrdiff_t t__ = savestack(L, p); /* save 'p' */ \ 43 | luaC_checkGC(L), /* stack grow uses memory */ \ 44 | p = restorestack(L, t__)) /* 'pos' part: restore 'p' */ 45 | 46 | 47 | /* macro to check stack size and GC */ 48 | #define checkstackGC(L,fsize) \ 49 | luaD_checkstackaux(L, (fsize), luaC_checkGC(L), (void)0) 50 | 51 | 52 | /* type of protected functions, to be ran by 'runprotected' */ 53 | typedef void (*Pfunc) (lua_State *L, void *ud); 54 | 55 | LUAI_FUNC void luaD_seterrorobj (lua_State *L, int errcode, StkId oldtop); 56 | LUAI_FUNC int luaD_protectedparser (lua_State *L, ZIO *z, const char *name, 57 | const char *mode); 58 | LUAI_FUNC void luaD_hook (lua_State *L, int event, int line, 59 | int fTransfer, int nTransfer); 60 | LUAI_FUNC void luaD_hookcall (lua_State *L, CallInfo *ci); 61 | LUAI_FUNC int luaD_pretailcall (lua_State *L, CallInfo *ci, StkId func, int narg1, int delta); 62 | LUAI_FUNC CallInfo *luaD_precall (lua_State *L, StkId func, int nResults); 63 | LUAI_FUNC void luaD_call (lua_State *L, StkId func, int nResults); 64 | LUAI_FUNC void luaD_callnoyield (lua_State *L, StkId func, int nResults); 65 | LUAI_FUNC StkId luaD_tryfuncTM (lua_State *L, StkId func); 66 | LUAI_FUNC int luaD_closeprotected (lua_State *L, ptrdiff_t level, int status); 67 | LUAI_FUNC int luaD_pcall (lua_State *L, Pfunc func, void *u, 68 | ptrdiff_t oldtop, ptrdiff_t ef); 69 | LUAI_FUNC void luaD_poscall (lua_State *L, CallInfo *ci, int nres); 70 | LUAI_FUNC int luaD_reallocstack (lua_State *L, int newsize, int raiseerror); 71 | LUAI_FUNC int luaD_growstack (lua_State *L, int n, int raiseerror); 72 | LUAI_FUNC void luaD_shrinkstack (lua_State *L); 73 | LUAI_FUNC void luaD_inctop (lua_State *L); 74 | 75 | LUAI_FUNC l_noret luaD_throw (lua_State *L, int errcode); 76 | LUAI_FUNC int luaD_rawrunprotected (lua_State *L, Pfunc f, void *ud); 77 | 78 | #endif 79 | 80 | -------------------------------------------------------------------------------- /externals/lua/src/ldump.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: ldump.c $ 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(D,v,n) dumpBlock(D,v,(n)*sizeof((v)[0])) 36 | 37 | #define dumpLiteral(D, s) dumpBlock(D,s,sizeof(s) - sizeof(char)) 38 | 39 | 40 | static void dumpBlock (DumpState *D, const void *b, size_t size) { 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(D,x) dumpVector(D,&x,1) 50 | 51 | 52 | static void dumpByte (DumpState *D, int y) { 53 | lu_byte x = (lu_byte)y; 54 | dumpVar(D, x); 55 | } 56 | 57 | 58 | /* dumpInt Buff Size */ 59 | #define DIBS ((sizeof(size_t) * 8 / 7) + 1) 60 | 61 | static void dumpSize (DumpState *D, size_t x) { 62 | lu_byte buff[DIBS]; 63 | int n = 0; 64 | do { 65 | buff[DIBS - (++n)] = x & 0x7f; /* fill buffer in reverse order */ 66 | x >>= 7; 67 | } while (x != 0); 68 | buff[DIBS - 1] |= 0x80; /* mark last byte */ 69 | dumpVector(D, buff + DIBS - n, n); 70 | } 71 | 72 | 73 | static void dumpInt (DumpState *D, int x) { 74 | dumpSize(D, x); 75 | } 76 | 77 | 78 | static void dumpNumber (DumpState *D, lua_Number x) { 79 | dumpVar(D, x); 80 | } 81 | 82 | 83 | static void dumpInteger (DumpState *D, lua_Integer x) { 84 | dumpVar(D, x); 85 | } 86 | 87 | 88 | static void dumpString (DumpState *D, const TString *s) { 89 | if (s == NULL) 90 | dumpSize(D, 0); 91 | else { 92 | size_t size = tsslen(s); 93 | const char *str = getstr(s); 94 | dumpSize(D, size + 1); 95 | dumpVector(D, str, size); 96 | } 97 | } 98 | 99 | 100 | static void dumpCode (DumpState *D, const Proto *f) { 101 | dumpInt(D, f->sizecode); 102 | dumpVector(D, f->code, f->sizecode); 103 | } 104 | 105 | 106 | static void dumpFunction(DumpState *D, const Proto *f, TString *psource); 107 | 108 | static void dumpConstants (DumpState *D, const Proto *f) { 109 | int i; 110 | int n = f->sizek; 111 | dumpInt(D, n); 112 | for (i = 0; i < n; i++) { 113 | const TValue *o = &f->k[i]; 114 | int tt = ttypetag(o); 115 | dumpByte(D, tt); 116 | switch (tt) { 117 | case LUA_VNUMFLT: 118 | dumpNumber(D, fltvalue(o)); 119 | break; 120 | case LUA_VNUMINT: 121 | dumpInteger(D, ivalue(o)); 122 | break; 123 | case LUA_VSHRSTR: 124 | case LUA_VLNGSTR: 125 | dumpString(D, tsvalue(o)); 126 | break; 127 | default: 128 | lua_assert(tt == LUA_VNIL || tt == LUA_VFALSE || tt == LUA_VTRUE); 129 | } 130 | } 131 | } 132 | 133 | 134 | static void dumpProtos (DumpState *D, const Proto *f) { 135 | int i; 136 | int n = f->sizep; 137 | dumpInt(D, n); 138 | for (i = 0; i < n; i++) 139 | dumpFunction(D, f->p[i], f->source); 140 | } 141 | 142 | 143 | static void dumpUpvalues (DumpState *D, const Proto *f) { 144 | int i, n = f->sizeupvalues; 145 | dumpInt(D, n); 146 | for (i = 0; i < n; i++) { 147 | dumpByte(D, f->upvalues[i].instack); 148 | dumpByte(D, f->upvalues[i].idx); 149 | dumpByte(D, f->upvalues[i].kind); 150 | } 151 | } 152 | 153 | 154 | static void dumpDebug (DumpState *D, const Proto *f) { 155 | int i, n; 156 | n = (D->strip) ? 0 : f->sizelineinfo; 157 | dumpInt(D, n); 158 | dumpVector(D, f->lineinfo, n); 159 | n = (D->strip) ? 0 : f->sizeabslineinfo; 160 | dumpInt(D, n); 161 | for (i = 0; i < n; i++) { 162 | dumpInt(D, f->abslineinfo[i].pc); 163 | dumpInt(D, f->abslineinfo[i].line); 164 | } 165 | n = (D->strip) ? 0 : f->sizelocvars; 166 | dumpInt(D, n); 167 | for (i = 0; i < n; i++) { 168 | dumpString(D, f->locvars[i].varname); 169 | dumpInt(D, f->locvars[i].startpc); 170 | dumpInt(D, f->locvars[i].endpc); 171 | } 172 | n = (D->strip) ? 0 : f->sizeupvalues; 173 | dumpInt(D, n); 174 | for (i = 0; i < n; i++) 175 | dumpString(D, f->upvalues[i].name); 176 | } 177 | 178 | 179 | static void dumpFunction (DumpState *D, const Proto *f, TString *psource) { 180 | if (D->strip || f->source == psource) 181 | dumpString(D, NULL); /* no debug info or same source as its parent */ 182 | else 183 | dumpString(D, f->source); 184 | dumpInt(D, f->linedefined); 185 | dumpInt(D, f->lastlinedefined); 186 | dumpByte(D, f->numparams); 187 | dumpByte(D, f->is_vararg); 188 | dumpByte(D, f->maxstacksize); 189 | dumpCode(D, f); 190 | dumpConstants(D, f); 191 | dumpUpvalues(D, f); 192 | dumpProtos(D, f); 193 | dumpDebug(D, f); 194 | } 195 | 196 | 197 | static void dumpHeader (DumpState *D) { 198 | dumpLiteral(D, LUA_SIGNATURE); 199 | dumpByte(D, LUAC_VERSION); 200 | dumpByte(D, LUAC_FORMAT); 201 | dumpLiteral(D, LUAC_DATA); 202 | dumpByte(D, sizeof(Instruction)); 203 | dumpByte(D, sizeof(lua_Integer)); 204 | dumpByte(D, sizeof(lua_Number)); 205 | dumpInteger(D, LUAC_INT); 206 | dumpNumber(D, LUAC_NUM); 207 | } 208 | 209 | 210 | /* 211 | ** dump Lua function as precompiled chunk 212 | */ 213 | int luaU_dump(lua_State *L, const Proto *f, lua_Writer w, void *data, 214 | int strip) { 215 | DumpState D; 216 | D.L = L; 217 | D.writer = w; 218 | D.data = data; 219 | D.strip = strip; 220 | D.status = 0; 221 | dumpHeader(&D); 222 | dumpByte(&D, f->sizeupvalues); 223 | dumpFunction(&D, f, NULL); 224 | return D.status; 225 | } 226 | 227 | -------------------------------------------------------------------------------- /externals/lua/src/lfunc.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lfunc.h $ 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(offsetof(CClosure, upvalue)) + \ 15 | cast_int(sizeof(TValue)) * (n)) 16 | 17 | #define sizeLclosure(n) (cast_int(offsetof(LClosure, upvals)) + \ 18 | cast_int(sizeof(TValue *)) * (n)) 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 | #define upisopen(up) ((up)->v != &(up)->u.value) 33 | 34 | 35 | #define uplevel(up) check_exp(upisopen(up), cast(StkId, (up)->v)) 36 | 37 | 38 | /* 39 | ** maximum number of misses before giving up the cache of closures 40 | ** in prototypes 41 | */ 42 | #define MAXMISS 10 43 | 44 | 45 | 46 | /* special status to close upvalues preserving the top of the stack */ 47 | #define CLOSEKTOP (-1) 48 | 49 | 50 | LUAI_FUNC Proto *luaF_newproto (lua_State *L); 51 | LUAI_FUNC CClosure *luaF_newCclosure (lua_State *L, int nupvals); 52 | LUAI_FUNC LClosure *luaF_newLclosure (lua_State *L, int nupvals); 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_newtbcupval (lua_State *L, StkId level); 56 | LUAI_FUNC void luaF_closeupval (lua_State *L, StkId level); 57 | LUAI_FUNC void luaF_close (lua_State *L, StkId level, int status, int yy); 58 | LUAI_FUNC void luaF_unlinkupval (UpVal *uv); 59 | LUAI_FUNC void luaF_freeproto (lua_State *L, Proto *f); 60 | LUAI_FUNC const char *luaF_getlocalname (const Proto *func, int local_number, 61 | int pc); 62 | 63 | 64 | #endif 65 | -------------------------------------------------------------------------------- /externals/lua/src/lgc.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lgc.h $ 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 means 16 | ** the object is not marked; gray, which means the object is marked, but 17 | ** its references may be not marked; and black, which means that the 18 | ** object and all its references are marked. The main invariant of the 19 | ** garbage collector, while marking objects, is that a black object can 20 | ** never point to a white one. Moreover, any gray object must be in a 21 | ** "gray list" (gray, grayagain, weak, allweak, ephemeron) so that it 22 | ** can be visited again before finishing the collection cycle. (Open 23 | ** upvalues are an exception to this rule.) These lists have no meaning 24 | ** when the invariant is not being enforced (e.g., sweep phase). 25 | */ 26 | 27 | 28 | /* 29 | ** Possible states of the Garbage Collector 30 | */ 31 | #define GCSpropagate 0 32 | #define GCSenteratomic 1 33 | #define GCSatomic 2 34 | #define GCSswpallgc 3 35 | #define GCSswpfinobj 4 36 | #define GCSswptobefnz 5 37 | #define GCSswpend 6 38 | #define GCScallfin 7 39 | #define GCSpause 8 40 | 41 | 42 | #define issweepphase(g) \ 43 | (GCSswpallgc <= (g)->gcstate && (g)->gcstate <= GCSswpend) 44 | 45 | 46 | /* 47 | ** macro to tell when main invariant (white objects cannot point to black 48 | ** ones) must be kept. During a collection, the sweep 49 | ** phase may break the invariant, as objects turned white may point to 50 | ** still-black objects. The invariant is restored when sweep ends and 51 | ** all objects are white again. 52 | */ 53 | 54 | #define keepinvariant(g) ((g)->gcstate <= GCSatomic) 55 | 56 | 57 | /* 58 | ** some useful bit tricks 59 | */ 60 | #define resetbits(x,m) ((x) &= cast_byte(~(m))) 61 | #define setbits(x,m) ((x) |= (m)) 62 | #define testbits(x,m) ((x) & (m)) 63 | #define bitmask(b) (1<<(b)) 64 | #define bit2mask(b1,b2) (bitmask(b1) | bitmask(b2)) 65 | #define l_setbit(x,b) setbits(x, bitmask(b)) 66 | #define resetbit(x,b) resetbits(x, bitmask(b)) 67 | #define testbit(x,b) testbits(x, bitmask(b)) 68 | 69 | 70 | /* 71 | ** Layout for bit use in 'marked' field. First three bits are 72 | ** used for object "age" in generational mode. Last bit is used 73 | ** by tests. 74 | */ 75 | #define WHITE0BIT 3 /* object is white (type 0) */ 76 | #define WHITE1BIT 4 /* object is white (type 1) */ 77 | #define BLACKBIT 5 /* object is black */ 78 | #define FINALIZEDBIT 6 /* object has been marked for finalization */ 79 | 80 | #define TESTBIT 7 81 | 82 | 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) & (ow)) 96 | #define isdead(g,v) isdeadm(otherwhite(g), (v)->marked) 97 | 98 | #define changewhite(x) ((x)->marked ^= WHITEBITS) 99 | #define nw2black(x) \ 100 | check_exp(!iswhite(x), l_setbit((x)->marked, BLACKBIT)) 101 | 102 | #define luaC_white(g) cast_byte((g)->currentwhite & WHITEBITS) 103 | 104 | 105 | /* object age in generational mode */ 106 | #define G_NEW 0 /* created in current cycle */ 107 | #define G_SURVIVAL 1 /* created in previous cycle */ 108 | #define G_OLD0 2 /* marked old by frw. barrier in this cycle */ 109 | #define G_OLD1 3 /* first full cycle as old */ 110 | #define G_OLD 4 /* really old object (not to be visited) */ 111 | #define G_TOUCHED1 5 /* old object touched this cycle */ 112 | #define G_TOUCHED2 6 /* old object touched in previous cycle */ 113 | 114 | #define AGEBITS 7 /* all age bits (111) */ 115 | 116 | #define getage(o) ((o)->marked & AGEBITS) 117 | #define setage(o,a) ((o)->marked = cast_byte(((o)->marked & (~AGEBITS)) | a)) 118 | #define isold(o) (getage(o) > G_SURVIVAL) 119 | 120 | #define changeage(o,f,t) \ 121 | check_exp(getage(o) == (f), (o)->marked ^= ((f)^(t))) 122 | 123 | 124 | /* Default Values for GC parameters */ 125 | #define LUAI_GENMAJORMUL 100 126 | #define LUAI_GENMINORMUL 20 127 | 128 | /* wait memory to double before starting new cycle */ 129 | #define LUAI_GCPAUSE 200 130 | 131 | /* 132 | ** some gc parameters are stored divided by 4 to allow a maximum value 133 | ** up to 1023 in a 'lu_byte'. 134 | */ 135 | #define getgcparam(p) ((p) * 4) 136 | #define setgcparam(p,v) ((p) = (v) / 4) 137 | 138 | #define LUAI_GCMUL 100 139 | 140 | /* how much to allocate before next GC step (log2) */ 141 | #define LUAI_GCSTEPSIZE 13 /* 8 KB */ 142 | 143 | 144 | /* 145 | ** Check whether the declared GC mode is generational. While in 146 | ** generational mode, the collector can go temporarily to incremental 147 | ** mode to improve performance. This is signaled by 'g->lastatomic != 0'. 148 | */ 149 | #define isdecGCmodegen(g) (g->gckind == KGC_GEN || g->lastatomic != 0) 150 | 151 | 152 | /* 153 | ** Control when GC is running: 154 | */ 155 | #define GCSTPUSR 1 /* bit true when GC stopped by user */ 156 | #define GCSTPGC 2 /* bit true when GC stopped by itself */ 157 | #define GCSTPCLS 4 /* bit true when closing Lua state */ 158 | #define gcrunning(g) ((g)->gcstp == 0) 159 | 160 | 161 | /* 162 | ** Does one step of collection when debt becomes positive. 'pre'/'pos' 163 | ** allows some adjustments to be done only when needed. macro 164 | ** 'condchangemem' is used only for heavy tests (forcing a full 165 | ** GC cycle on every opportunity) 166 | */ 167 | #define luaC_condGC(L,pre,pos) \ 168 | { if (G(L)->GCdebt > 0) { pre; luaC_step(L); pos;}; \ 169 | condchangemem(L,pre,pos); } 170 | 171 | /* more often than not, 'pre'/'pos' are empty */ 172 | #define luaC_checkGC(L) luaC_condGC(L,(void)0,(void)0) 173 | 174 | 175 | #define luaC_barrier(L,p,v) ( \ 176 | (iscollectable(v) && isblack(p) && iswhite(gcvalue(v))) ? \ 177 | luaC_barrier_(L,obj2gco(p),gcvalue(v)) : cast_void(0)) 178 | 179 | #define luaC_barrierback(L,p,v) ( \ 180 | (iscollectable(v) && isblack(p) && iswhite(gcvalue(v))) ? \ 181 | luaC_barrierback_(L,p) : cast_void(0)) 182 | 183 | #define luaC_objbarrier(L,p,o) ( \ 184 | (isblack(p) && iswhite(o)) ? \ 185 | luaC_barrier_(L,obj2gco(p),obj2gco(o)) : cast_void(0)) 186 | 187 | LUAI_FUNC void luaC_fix (lua_State *L, GCObject *o); 188 | LUAI_FUNC void luaC_freeallobjects (lua_State *L); 189 | LUAI_FUNC void luaC_step (lua_State *L); 190 | LUAI_FUNC void luaC_runtilstate (lua_State *L, int statesmask); 191 | LUAI_FUNC void luaC_fullgc (lua_State *L, int isemergency); 192 | LUAI_FUNC GCObject *luaC_newobj (lua_State *L, int tt, size_t sz); 193 | LUAI_FUNC void luaC_barrier_ (lua_State *L, GCObject *o, GCObject *v); 194 | LUAI_FUNC void luaC_barrierback_ (lua_State *L, GCObject *o); 195 | LUAI_FUNC void luaC_checkfinalizer (lua_State *L, GCObject *o, Table *mt); 196 | LUAI_FUNC void luaC_changemode (lua_State *L, int newmode); 197 | 198 | 199 | #endif 200 | -------------------------------------------------------------------------------- /externals/lua/src/linit.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: linit.c $ 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 | {LUA_GNAME, 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 | {NULL, NULL} 54 | }; 55 | 56 | 57 | LUALIB_API void luaL_openlibs (lua_State *L) { 58 | const luaL_Reg *lib; 59 | /* "require" functions from 'loadedlibs' and set results to global table */ 60 | for (lib = loadedlibs; lib->func; lib++) { 61 | luaL_requiref(L, lib->name, lib->func, 1); 62 | lua_pop(L, 1); /* remove lib */ 63 | } 64 | } 65 | 66 | -------------------------------------------------------------------------------- /externals/lua/src/ljumptab.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: ljumptab.h $ 3 | ** Jump Table for the Lua interpreter 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | 8 | #undef vmdispatch 9 | #undef vmcase 10 | #undef vmbreak 11 | 12 | #define vmdispatch(x) goto *disptab[x]; 13 | 14 | #define vmcase(l) L_##l: 15 | 16 | #define vmbreak vmfetch(); vmdispatch(GET_OPCODE(i)); 17 | 18 | 19 | static const void *const disptab[NUM_OPCODES] = { 20 | 21 | #if 0 22 | ** you can update the following list with this command: 23 | ** 24 | ** sed -n '/^OP_/\!d; s/OP_/\&\&L_OP_/ ; s/,.*/,/ ; s/\/.*// ; p' lopcodes.h 25 | ** 26 | #endif 27 | 28 | &&L_OP_MOVE, 29 | &&L_OP_LOADI, 30 | &&L_OP_LOADF, 31 | &&L_OP_LOADK, 32 | &&L_OP_LOADKX, 33 | &&L_OP_LOADFALSE, 34 | &&L_OP_LFALSESKIP, 35 | &&L_OP_LOADTRUE, 36 | &&L_OP_LOADNIL, 37 | &&L_OP_GETUPVAL, 38 | &&L_OP_SETUPVAL, 39 | &&L_OP_GETTABUP, 40 | &&L_OP_GETTABLE, 41 | &&L_OP_GETI, 42 | &&L_OP_GETFIELD, 43 | &&L_OP_SETTABUP, 44 | &&L_OP_SETTABLE, 45 | &&L_OP_SETI, 46 | &&L_OP_SETFIELD, 47 | &&L_OP_NEWTABLE, 48 | &&L_OP_SELF, 49 | &&L_OP_ADDI, 50 | &&L_OP_ADDK, 51 | &&L_OP_SUBK, 52 | &&L_OP_MULK, 53 | &&L_OP_MODK, 54 | &&L_OP_POWK, 55 | &&L_OP_DIVK, 56 | &&L_OP_IDIVK, 57 | &&L_OP_BANDK, 58 | &&L_OP_BORK, 59 | &&L_OP_BXORK, 60 | &&L_OP_SHRI, 61 | &&L_OP_SHLI, 62 | &&L_OP_ADD, 63 | &&L_OP_SUB, 64 | &&L_OP_MUL, 65 | &&L_OP_MOD, 66 | &&L_OP_POW, 67 | &&L_OP_DIV, 68 | &&L_OP_IDIV, 69 | &&L_OP_BAND, 70 | &&L_OP_BOR, 71 | &&L_OP_BXOR, 72 | &&L_OP_SHL, 73 | &&L_OP_SHR, 74 | &&L_OP_MMBIN, 75 | &&L_OP_MMBINI, 76 | &&L_OP_MMBINK, 77 | &&L_OP_UNM, 78 | &&L_OP_BNOT, 79 | &&L_OP_NOT, 80 | &&L_OP_LEN, 81 | &&L_OP_CONCAT, 82 | &&L_OP_CLOSE, 83 | &&L_OP_TBC, 84 | &&L_OP_JMP, 85 | &&L_OP_EQ, 86 | &&L_OP_LT, 87 | &&L_OP_LE, 88 | &&L_OP_EQK, 89 | &&L_OP_EQI, 90 | &&L_OP_LTI, 91 | &&L_OP_LEI, 92 | &&L_OP_GTI, 93 | &&L_OP_GEI, 94 | &&L_OP_TEST, 95 | &&L_OP_TESTSET, 96 | &&L_OP_CALL, 97 | &&L_OP_TAILCALL, 98 | &&L_OP_RETURN, 99 | &&L_OP_RETURN0, 100 | &&L_OP_RETURN1, 101 | &&L_OP_FORLOOP, 102 | &&L_OP_FORPREP, 103 | &&L_OP_TFORPREP, 104 | &&L_OP_TFORCALL, 105 | &&L_OP_TFORLOOP, 106 | &&L_OP_SETLIST, 107 | &&L_OP_CLOSURE, 108 | &&L_OP_VARARG, 109 | &&L_OP_VARARGPREP, 110 | &&L_OP_EXTRAARG 111 | 112 | }; 113 | -------------------------------------------------------------------------------- /externals/lua/src/llex.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: llex.h $ 3 | ** Lexical Analyzer 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef llex_h 8 | #define llex_h 9 | 10 | #include 11 | 12 | #include "lobject.h" 13 | #include "lzio.h" 14 | 15 | 16 | /* 17 | ** Single-char tokens (terminal symbols) are represented by their own 18 | ** numeric code. Other tokens start at the following value. 19 | */ 20 | #define FIRST_RESERVED (UCHAR_MAX + 1) 21 | 22 | 23 | #if !defined(LUA_ENV) 24 | #define LUA_ENV "_ENV" 25 | #endif 26 | 27 | 28 | /* 29 | * WARNING: if you change the order of this enumeration, 30 | * grep "ORDER RESERVED" 31 | */ 32 | enum RESERVED { 33 | /* terminal symbols denoted by reserved words */ 34 | TK_AND = FIRST_RESERVED, TK_BREAK, 35 | TK_DO, TK_ELSE, TK_ELSEIF, TK_END, TK_FALSE, TK_FOR, TK_FUNCTION, 36 | TK_GOTO, TK_IF, TK_IN, TK_LOCAL, TK_NIL, TK_NOT, TK_OR, TK_REPEAT, 37 | TK_RETURN, TK_THEN, TK_TRUE, TK_UNTIL, TK_WHILE, 38 | /* other terminal symbols */ 39 | TK_IDIV, TK_CONCAT, TK_DOTS, TK_EQ, TK_GE, TK_LE, TK_NE, 40 | TK_SHL, TK_SHR, 41 | TK_DBCOLON, TK_EOS, 42 | TK_FLT, TK_INT, TK_NAME, TK_STRING 43 | }; 44 | 45 | /* number of reserved words */ 46 | #define NUM_RESERVED (cast_int(TK_WHILE-FIRST_RESERVED + 1)) 47 | 48 | 49 | typedef union { 50 | lua_Number r; 51 | lua_Integer i; 52 | TString *ts; 53 | } SemInfo; /* semantics information */ 54 | 55 | 56 | typedef struct Token { 57 | int token; 58 | SemInfo seminfo; 59 | } Token; 60 | 61 | 62 | /* state of the lexer plus state of the parser when shared by all 63 | functions */ 64 | typedef struct LexState { 65 | int current; /* current character (charint) */ 66 | int linenumber; /* input line counter */ 67 | int lastline; /* line of last token 'consumed' */ 68 | Token t; /* current token */ 69 | Token lookahead; /* look ahead token */ 70 | struct FuncState *fs; /* current function (parser) */ 71 | struct lua_State *L; 72 | ZIO *z; /* input stream */ 73 | Mbuffer *buff; /* buffer for tokens */ 74 | Table *h; /* to avoid collection/reuse strings */ 75 | struct Dyndata *dyd; /* dynamic structures used by the parser */ 76 | TString *source; /* current source name */ 77 | TString *envn; /* environment variable name */ 78 | } LexState; 79 | 80 | 81 | LUAI_FUNC void luaX_init (lua_State *L); 82 | LUAI_FUNC void luaX_setinput (lua_State *L, LexState *ls, ZIO *z, 83 | TString *source, int firstchar); 84 | LUAI_FUNC TString *luaX_newstring (LexState *ls, const char *str, size_t l); 85 | LUAI_FUNC void luaX_next (LexState *ls); 86 | LUAI_FUNC int luaX_lookahead (LexState *ls); 87 | LUAI_FUNC l_noret luaX_syntaxerror (LexState *ls, const char *s); 88 | LUAI_FUNC const char *luaX_token2str (LexState *ls, int token); 89 | 90 | 91 | #endif 92 | -------------------------------------------------------------------------------- /externals/lua/src/lmem.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lmem.c $ 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 | #if defined(EMERGENCYGCTESTS) 26 | /* 27 | ** First allocation will fail whenever not building initial state. 28 | ** (This fail will trigger 'tryagain' and a full GC cycle at every 29 | ** allocation.) 30 | */ 31 | static void *firsttry (global_State *g, void *block, size_t os, size_t ns) { 32 | if (completestate(g) && ns > 0) /* frees never fail */ 33 | return NULL; /* fail */ 34 | else /* normal allocation */ 35 | return (*g->frealloc)(g->ud, block, os, ns); 36 | } 37 | #else 38 | #define firsttry(g,block,os,ns) ((*g->frealloc)(g->ud, block, os, ns)) 39 | #endif 40 | 41 | 42 | 43 | 44 | 45 | /* 46 | ** About the realloc function: 47 | ** void *frealloc (void *ud, void *ptr, size_t osize, size_t nsize); 48 | ** ('osize' is the old size, 'nsize' is the new size) 49 | ** 50 | ** - frealloc(ud, p, x, 0) frees the block 'p' and returns NULL. 51 | ** Particularly, frealloc(ud, NULL, 0, 0) does nothing, 52 | ** which is equivalent to free(NULL) in ISO C. 53 | ** 54 | ** - frealloc(ud, NULL, x, s) creates a new block of size 's' 55 | ** (no matter 'x'). Returns NULL if it cannot create the new block. 56 | ** 57 | ** - otherwise, frealloc(ud, b, x, y) reallocates the block 'b' from 58 | ** size 'x' to size 'y'. Returns NULL if it cannot reallocate the 59 | ** block to the new size. 60 | */ 61 | 62 | 63 | 64 | 65 | /* 66 | ** {================================================================== 67 | ** Functions to allocate/deallocate arrays for the Parser 68 | ** =================================================================== 69 | */ 70 | 71 | /* 72 | ** Minimum size for arrays during parsing, to avoid overhead of 73 | ** reallocating to size 1, then 2, and then 4. All these arrays 74 | ** will be reallocated to exact sizes or erased when parsing ends. 75 | */ 76 | #define MINSIZEARRAY 4 77 | 78 | 79 | void *luaM_growaux_ (lua_State *L, void *block, int nelems, int *psize, 80 | int size_elems, int limit, const char *what) { 81 | void *newblock; 82 | int size = *psize; 83 | if (nelems + 1 <= size) /* does one extra element still fit? */ 84 | return block; /* nothing to be done */ 85 | if (size >= limit / 2) { /* cannot double it? */ 86 | if (l_unlikely(size >= limit)) /* cannot grow even a little? */ 87 | luaG_runerror(L, "too many %s (limit is %d)", what, limit); 88 | size = limit; /* still have at least one free place */ 89 | } 90 | else { 91 | size *= 2; 92 | if (size < MINSIZEARRAY) 93 | size = MINSIZEARRAY; /* minimum size */ 94 | } 95 | lua_assert(nelems + 1 <= size && size <= limit); 96 | /* 'limit' ensures that multiplication will not overflow */ 97 | newblock = luaM_saferealloc_(L, block, cast_sizet(*psize) * size_elems, 98 | cast_sizet(size) * size_elems); 99 | *psize = size; /* update only when everything else is OK */ 100 | return newblock; 101 | } 102 | 103 | 104 | /* 105 | ** In prototypes, the size of the array is also its number of 106 | ** elements (to save memory). So, if it cannot shrink an array 107 | ** to its number of elements, the only option is to raise an 108 | ** error. 109 | */ 110 | void *luaM_shrinkvector_ (lua_State *L, void *block, int *size, 111 | int final_n, int size_elem) { 112 | void *newblock; 113 | size_t oldsize = cast_sizet((*size) * size_elem); 114 | size_t newsize = cast_sizet(final_n * size_elem); 115 | lua_assert(newsize <= oldsize); 116 | newblock = luaM_saferealloc_(L, block, oldsize, newsize); 117 | *size = final_n; 118 | return newblock; 119 | } 120 | 121 | /* }================================================================== */ 122 | 123 | 124 | l_noret luaM_toobig (lua_State *L) { 125 | luaG_runerror(L, "memory allocation error: block too big"); 126 | } 127 | 128 | 129 | /* 130 | ** Free memory 131 | */ 132 | void luaM_free_ (lua_State *L, void *block, size_t osize) { 133 | global_State *g = G(L); 134 | lua_assert((osize == 0) == (block == NULL)); 135 | (*g->frealloc)(g->ud, block, osize, 0); 136 | g->GCdebt -= osize; 137 | } 138 | 139 | 140 | /* 141 | ** In case of allocation fail, this function will do an emergency 142 | ** collection to free some memory and then try the allocation again. 143 | ** The GC should not be called while state is not fully built, as the 144 | ** collector is not yet fully initialized. Also, it should not be called 145 | ** when 'gcstopem' is true, because then the interpreter is in the 146 | ** middle of a collection step. 147 | */ 148 | static void *tryagain (lua_State *L, void *block, 149 | size_t osize, size_t nsize) { 150 | global_State *g = G(L); 151 | if (completestate(g) && !g->gcstopem) { 152 | luaC_fullgc(L, 1); /* try to free some memory... */ 153 | return (*g->frealloc)(g->ud, block, osize, nsize); /* try again */ 154 | } 155 | else return NULL; /* cannot free any memory without a full state */ 156 | } 157 | 158 | 159 | /* 160 | ** Generic allocation routine. 161 | */ 162 | void *luaM_realloc_ (lua_State *L, void *block, size_t osize, size_t nsize) { 163 | void *newblock; 164 | global_State *g = G(L); 165 | lua_assert((osize == 0) == (block == NULL)); 166 | newblock = firsttry(g, block, osize, nsize); 167 | if (l_unlikely(newblock == NULL && nsize > 0)) { 168 | newblock = tryagain(L, block, osize, nsize); 169 | if (newblock == NULL) /* still no memory? */ 170 | return NULL; /* do not update 'GCdebt' */ 171 | } 172 | lua_assert((nsize == 0) == (newblock == NULL)); 173 | g->GCdebt = (g->GCdebt + nsize) - osize; 174 | return newblock; 175 | } 176 | 177 | 178 | void *luaM_saferealloc_ (lua_State *L, void *block, size_t osize, 179 | size_t nsize) { 180 | void *newblock = luaM_realloc_(L, block, osize, nsize); 181 | if (l_unlikely(newblock == NULL && nsize > 0)) /* allocation failed? */ 182 | luaM_error(L); 183 | return newblock; 184 | } 185 | 186 | 187 | void *luaM_malloc_ (lua_State *L, size_t size, int tag) { 188 | if (size == 0) 189 | return NULL; /* that's all */ 190 | else { 191 | global_State *g = G(L); 192 | void *newblock = firsttry(g, NULL, tag, size); 193 | if (l_unlikely(newblock == NULL)) { 194 | newblock = tryagain(L, NULL, tag, size); 195 | if (newblock == NULL) 196 | luaM_error(L); 197 | } 198 | g->GCdebt += size; 199 | return newblock; 200 | } 201 | } 202 | -------------------------------------------------------------------------------- /externals/lua/src/lmem.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lmem.h $ 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 | #define luaM_error(L) luaD_throw(L, LUA_ERRMEM) 18 | 19 | 20 | /* 21 | ** This macro tests whether it is safe to multiply 'n' by the size of 22 | ** type 't' without overflows. Because 'e' is always constant, it avoids 23 | ** the runtime division MAX_SIZET/(e). 24 | ** (The macro is somewhat complex to avoid warnings: The 'sizeof' 25 | ** comparison avoids a runtime comparison when overflow cannot occur. 26 | ** The compiler should be able to optimize the real test by itself, but 27 | ** when it does it, it may give a warning about "comparison is always 28 | ** false due to limited range of data type"; the +1 tricks the compiler, 29 | ** avoiding this warning but also this optimization.) 30 | */ 31 | #define luaM_testsize(n,e) \ 32 | (sizeof(n) >= sizeof(size_t) && cast_sizet((n)) + 1 > MAX_SIZET/(e)) 33 | 34 | #define luaM_checksize(L,n,e) \ 35 | (luaM_testsize(n,e) ? luaM_toobig(L) : cast_void(0)) 36 | 37 | 38 | /* 39 | ** Computes the minimum between 'n' and 'MAX_SIZET/sizeof(t)', so that 40 | ** the result is not larger than 'n' and cannot overflow a 'size_t' 41 | ** when multiplied by the size of type 't'. (Assumes that 'n' is an 42 | ** 'int' or 'unsigned int' and that 'int' is not larger than 'size_t'.) 43 | */ 44 | #define luaM_limitN(n,t) \ 45 | ((cast_sizet(n) <= MAX_SIZET/sizeof(t)) ? (n) : \ 46 | cast_uint((MAX_SIZET/sizeof(t)))) 47 | 48 | 49 | /* 50 | ** Arrays of chars do not need any test 51 | */ 52 | #define luaM_reallocvchar(L,b,on,n) \ 53 | cast_charp(luaM_saferealloc_(L, (b), (on)*sizeof(char), (n)*sizeof(char))) 54 | 55 | #define luaM_freemem(L, b, s) luaM_free_(L, (b), (s)) 56 | #define luaM_free(L, b) luaM_free_(L, (b), sizeof(*(b))) 57 | #define luaM_freearray(L, b, n) luaM_free_(L, (b), (n)*sizeof(*(b))) 58 | 59 | #define luaM_new(L,t) cast(t*, luaM_malloc_(L, sizeof(t), 0)) 60 | #define luaM_newvector(L,n,t) cast(t*, luaM_malloc_(L, (n)*sizeof(t), 0)) 61 | #define luaM_newvectorchecked(L,n,t) \ 62 | (luaM_checksize(L,n,sizeof(t)), luaM_newvector(L,n,t)) 63 | 64 | #define luaM_newobject(L,tag,s) luaM_malloc_(L, (s), tag) 65 | 66 | #define luaM_growvector(L,v,nelems,size,t,limit,e) \ 67 | ((v)=cast(t *, luaM_growaux_(L,v,nelems,&(size),sizeof(t), \ 68 | luaM_limitN(limit,t),e))) 69 | 70 | #define luaM_reallocvector(L, v,oldn,n,t) \ 71 | (cast(t *, luaM_realloc_(L, v, cast_sizet(oldn) * sizeof(t), \ 72 | cast_sizet(n) * sizeof(t)))) 73 | 74 | #define luaM_shrinkvector(L,v,size,fs,t) \ 75 | ((v)=cast(t *, luaM_shrinkvector_(L, v, &(size), fs, sizeof(t)))) 76 | 77 | LUAI_FUNC l_noret luaM_toobig (lua_State *L); 78 | 79 | /* not to be called directly */ 80 | LUAI_FUNC void *luaM_realloc_ (lua_State *L, void *block, size_t oldsize, 81 | size_t size); 82 | LUAI_FUNC void *luaM_saferealloc_ (lua_State *L, void *block, size_t oldsize, 83 | size_t size); 84 | LUAI_FUNC void luaM_free_ (lua_State *L, void *block, size_t osize); 85 | LUAI_FUNC void *luaM_growaux_ (lua_State *L, void *block, int nelems, 86 | int *size, int size_elem, int limit, 87 | const char *what); 88 | LUAI_FUNC void *luaM_shrinkvector_ (lua_State *L, void *block, int *nelem, 89 | int final_n, int size_elem); 90 | LUAI_FUNC void *luaM_malloc_ (lua_State *L, size_t size, int tag); 91 | 92 | #endif 93 | 94 | -------------------------------------------------------------------------------- /externals/lua/src/lopcodes.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lopcodes.c $ 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 "lopcodes.h" 14 | 15 | 16 | /* ORDER OP */ 17 | 18 | LUAI_DDEF const lu_byte luaP_opmodes[NUM_OPCODES] = { 19 | /* MM OT IT T A mode opcode */ 20 | opmode(0, 0, 0, 0, 1, iABC) /* OP_MOVE */ 21 | ,opmode(0, 0, 0, 0, 1, iAsBx) /* OP_LOADI */ 22 | ,opmode(0, 0, 0, 0, 1, iAsBx) /* OP_LOADF */ 23 | ,opmode(0, 0, 0, 0, 1, iABx) /* OP_LOADK */ 24 | ,opmode(0, 0, 0, 0, 1, iABx) /* OP_LOADKX */ 25 | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_LOADFALSE */ 26 | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_LFALSESKIP */ 27 | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_LOADTRUE */ 28 | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_LOADNIL */ 29 | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_GETUPVAL */ 30 | ,opmode(0, 0, 0, 0, 0, iABC) /* OP_SETUPVAL */ 31 | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_GETTABUP */ 32 | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_GETTABLE */ 33 | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_GETI */ 34 | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_GETFIELD */ 35 | ,opmode(0, 0, 0, 0, 0, iABC) /* OP_SETTABUP */ 36 | ,opmode(0, 0, 0, 0, 0, iABC) /* OP_SETTABLE */ 37 | ,opmode(0, 0, 0, 0, 0, iABC) /* OP_SETI */ 38 | ,opmode(0, 0, 0, 0, 0, iABC) /* OP_SETFIELD */ 39 | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_NEWTABLE */ 40 | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_SELF */ 41 | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_ADDI */ 42 | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_ADDK */ 43 | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_SUBK */ 44 | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_MULK */ 45 | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_MODK */ 46 | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_POWK */ 47 | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_DIVK */ 48 | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_IDIVK */ 49 | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_BANDK */ 50 | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_BORK */ 51 | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_BXORK */ 52 | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_SHRI */ 53 | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_SHLI */ 54 | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_ADD */ 55 | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_SUB */ 56 | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_MUL */ 57 | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_MOD */ 58 | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_POW */ 59 | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_DIV */ 60 | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_IDIV */ 61 | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_BAND */ 62 | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_BOR */ 63 | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_BXOR */ 64 | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_SHL */ 65 | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_SHR */ 66 | ,opmode(1, 0, 0, 0, 0, iABC) /* OP_MMBIN */ 67 | ,opmode(1, 0, 0, 0, 0, iABC) /* OP_MMBINI*/ 68 | ,opmode(1, 0, 0, 0, 0, iABC) /* OP_MMBINK*/ 69 | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_UNM */ 70 | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_BNOT */ 71 | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_NOT */ 72 | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_LEN */ 73 | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_CONCAT */ 74 | ,opmode(0, 0, 0, 0, 0, iABC) /* OP_CLOSE */ 75 | ,opmode(0, 0, 0, 0, 0, iABC) /* OP_TBC */ 76 | ,opmode(0, 0, 0, 0, 0, isJ) /* OP_JMP */ 77 | ,opmode(0, 0, 0, 1, 0, iABC) /* OP_EQ */ 78 | ,opmode(0, 0, 0, 1, 0, iABC) /* OP_LT */ 79 | ,opmode(0, 0, 0, 1, 0, iABC) /* OP_LE */ 80 | ,opmode(0, 0, 0, 1, 0, iABC) /* OP_EQK */ 81 | ,opmode(0, 0, 0, 1, 0, iABC) /* OP_EQI */ 82 | ,opmode(0, 0, 0, 1, 0, iABC) /* OP_LTI */ 83 | ,opmode(0, 0, 0, 1, 0, iABC) /* OP_LEI */ 84 | ,opmode(0, 0, 0, 1, 0, iABC) /* OP_GTI */ 85 | ,opmode(0, 0, 0, 1, 0, iABC) /* OP_GEI */ 86 | ,opmode(0, 0, 0, 1, 0, iABC) /* OP_TEST */ 87 | ,opmode(0, 0, 0, 1, 1, iABC) /* OP_TESTSET */ 88 | ,opmode(0, 1, 1, 0, 1, iABC) /* OP_CALL */ 89 | ,opmode(0, 1, 1, 0, 1, iABC) /* OP_TAILCALL */ 90 | ,opmode(0, 0, 1, 0, 0, iABC) /* OP_RETURN */ 91 | ,opmode(0, 0, 0, 0, 0, iABC) /* OP_RETURN0 */ 92 | ,opmode(0, 0, 0, 0, 0, iABC) /* OP_RETURN1 */ 93 | ,opmode(0, 0, 0, 0, 1, iABx) /* OP_FORLOOP */ 94 | ,opmode(0, 0, 0, 0, 1, iABx) /* OP_FORPREP */ 95 | ,opmode(0, 0, 0, 0, 0, iABx) /* OP_TFORPREP */ 96 | ,opmode(0, 0, 0, 0, 0, iABC) /* OP_TFORCALL */ 97 | ,opmode(0, 0, 0, 0, 1, iABx) /* OP_TFORLOOP */ 98 | ,opmode(0, 0, 1, 0, 0, iABC) /* OP_SETLIST */ 99 | ,opmode(0, 0, 0, 0, 1, iABx) /* OP_CLOSURE */ 100 | ,opmode(0, 1, 0, 0, 1, iABC) /* OP_VARARG */ 101 | ,opmode(0, 0, 1, 0, 1, iABC) /* OP_VARARGPREP */ 102 | ,opmode(0, 0, 0, 0, 0, iAx) /* OP_EXTRAARG */ 103 | }; 104 | 105 | -------------------------------------------------------------------------------- /externals/lua/src/lopnames.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lopnames.h $ 3 | ** Opcode names 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #if !defined(lopnames_h) 8 | #define lopnames_h 9 | 10 | #include 11 | 12 | 13 | /* ORDER OP */ 14 | 15 | static const char *const opnames[] = { 16 | "MOVE", 17 | "LOADI", 18 | "LOADF", 19 | "LOADK", 20 | "LOADKX", 21 | "LOADFALSE", 22 | "LFALSESKIP", 23 | "LOADTRUE", 24 | "LOADNIL", 25 | "GETUPVAL", 26 | "SETUPVAL", 27 | "GETTABUP", 28 | "GETTABLE", 29 | "GETI", 30 | "GETFIELD", 31 | "SETTABUP", 32 | "SETTABLE", 33 | "SETI", 34 | "SETFIELD", 35 | "NEWTABLE", 36 | "SELF", 37 | "ADDI", 38 | "ADDK", 39 | "SUBK", 40 | "MULK", 41 | "MODK", 42 | "POWK", 43 | "DIVK", 44 | "IDIVK", 45 | "BANDK", 46 | "BORK", 47 | "BXORK", 48 | "SHRI", 49 | "SHLI", 50 | "ADD", 51 | "SUB", 52 | "MUL", 53 | "MOD", 54 | "POW", 55 | "DIV", 56 | "IDIV", 57 | "BAND", 58 | "BOR", 59 | "BXOR", 60 | "SHL", 61 | "SHR", 62 | "MMBIN", 63 | "MMBINI", 64 | "MMBINK", 65 | "UNM", 66 | "BNOT", 67 | "NOT", 68 | "LEN", 69 | "CONCAT", 70 | "CLOSE", 71 | "TBC", 72 | "JMP", 73 | "EQ", 74 | "LT", 75 | "LE", 76 | "EQK", 77 | "EQI", 78 | "LTI", 79 | "LEI", 80 | "GTI", 81 | "GEI", 82 | "TEST", 83 | "TESTSET", 84 | "CALL", 85 | "TAILCALL", 86 | "RETURN", 87 | "RETURN0", 88 | "RETURN1", 89 | "FORLOOP", 90 | "FORPREP", 91 | "TFORPREP", 92 | "TFORCALL", 93 | "TFORLOOP", 94 | "SETLIST", 95 | "CLOSURE", 96 | "VARARG", 97 | "VARARGPREP", 98 | "EXTRAARG", 99 | NULL 100 | }; 101 | 102 | #endif 103 | 104 | -------------------------------------------------------------------------------- /externals/lua/src/lparser.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lparser.h $ 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 of 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; ival = numerical integer value */ 34 | VKSTR, /* string constant; strval = TString address; 35 | (string is fixed by the lexer) */ 36 | VNONRELOC, /* expression has its value in a fixed register; 37 | info = result register */ 38 | VLOCAL, /* local variable; var.ridx = register index; 39 | var.vidx = relative index in 'actvar.arr' */ 40 | VUPVAL, /* upvalue variable; info = index of upvalue in 'upvalues' */ 41 | VCONST, /* compile-time variable; 42 | info = absolute index in 'actvar.arr' */ 43 | VINDEXED, /* indexed variable; 44 | ind.t = table register; 45 | ind.idx = key's R index */ 46 | VINDEXUP, /* indexed upvalue; 47 | ind.t = table upvalue; 48 | ind.idx = key's K index */ 49 | VINDEXI, /* indexed variable with constant integer; 50 | ind.t = table register; 51 | ind.idx = key's value */ 52 | VINDEXSTR, /* indexed variable with literal string; 53 | ind.t = table register; 54 | ind.idx = key's K index */ 55 | VJMP, /* expression is a test/comparison; 56 | info = pc of corresponding jump instruction */ 57 | VRELOC, /* expression can put result in any register; 58 | info = instruction pc */ 59 | VCALL, /* expression is a function call; info = instruction pc */ 60 | VVARARG /* vararg expression; info = instruction pc */ 61 | } expkind; 62 | 63 | 64 | #define vkisvar(k) (VLOCAL <= (k) && (k) <= VINDEXSTR) 65 | #define vkisindexed(k) (VINDEXED <= (k) && (k) <= VINDEXSTR) 66 | 67 | 68 | typedef struct expdesc { 69 | expkind k; 70 | union { 71 | lua_Integer ival; /* for VKINT */ 72 | lua_Number nval; /* for VKFLT */ 73 | TString *strval; /* for VKSTR */ 74 | int info; /* for generic use */ 75 | struct { /* for indexed variables */ 76 | short idx; /* index (R or "long" K) */ 77 | lu_byte t; /* table (register or upvalue) */ 78 | } ind; 79 | struct { /* for local variables */ 80 | lu_byte ridx; /* register holding the variable */ 81 | unsigned short vidx; /* compiler index (in 'actvar.arr') */ 82 | } var; 83 | } u; 84 | int t; /* patch list of 'exit when true' */ 85 | int f; /* patch list of 'exit when false' */ 86 | } expdesc; 87 | 88 | 89 | /* kinds of variables */ 90 | #define VDKREG 0 /* regular */ 91 | #define RDKCONST 1 /* constant */ 92 | #define RDKTOCLOSE 2 /* to-be-closed */ 93 | #define RDKCTC 3 /* compile-time constant */ 94 | 95 | /* description of an active local variable */ 96 | typedef union Vardesc { 97 | struct { 98 | TValuefields; /* constant value (if it is a compile-time constant) */ 99 | lu_byte kind; 100 | lu_byte ridx; /* register holding the variable */ 101 | short pidx; /* index of the variable in the Proto's 'locvars' array */ 102 | TString *name; /* variable name */ 103 | } vd; 104 | TValue k; /* constant value (if any) */ 105 | } Vardesc; 106 | 107 | 108 | 109 | /* description of pending goto statements and label statements */ 110 | typedef struct Labeldesc { 111 | TString *name; /* label identifier */ 112 | int pc; /* position in code */ 113 | int line; /* line where it appeared */ 114 | lu_byte nactvar; /* number of active variables in that position */ 115 | lu_byte close; /* goto that escapes upvalues */ 116 | } Labeldesc; 117 | 118 | 119 | /* list of labels or gotos */ 120 | typedef struct Labellist { 121 | Labeldesc *arr; /* array */ 122 | int n; /* number of entries in use */ 123 | int size; /* array size */ 124 | } Labellist; 125 | 126 | 127 | /* dynamic structures used by the parser */ 128 | typedef struct Dyndata { 129 | struct { /* list of all active local variables */ 130 | Vardesc *arr; 131 | int n; 132 | int size; 133 | } actvar; 134 | Labellist gt; /* list of pending gotos */ 135 | Labellist label; /* list of active labels */ 136 | } Dyndata; 137 | 138 | 139 | /* control of blocks */ 140 | struct BlockCnt; /* defined in lparser.c */ 141 | 142 | 143 | /* state needed to generate code for a given function */ 144 | typedef struct FuncState { 145 | Proto *f; /* current function header */ 146 | struct FuncState *prev; /* enclosing function */ 147 | struct LexState *ls; /* lexical state */ 148 | struct BlockCnt *bl; /* chain of current blocks */ 149 | int pc; /* next position to code (equivalent to 'ncode') */ 150 | int lasttarget; /* 'label' of last 'jump label' */ 151 | int previousline; /* last line that was saved in 'lineinfo' */ 152 | int nk; /* number of elements in 'k' */ 153 | int np; /* number of elements in 'p' */ 154 | int nabslineinfo; /* number of elements in 'abslineinfo' */ 155 | int firstlocal; /* index of first local var (in Dyndata array) */ 156 | int firstlabel; /* index of first label (in 'dyd->label->arr') */ 157 | short ndebugvars; /* number of elements in 'f->locvars' */ 158 | lu_byte nactvar; /* number of active local variables */ 159 | lu_byte nups; /* number of upvalues */ 160 | lu_byte freereg; /* first free register */ 161 | lu_byte iwthabs; /* instructions issued since last absolute line info */ 162 | lu_byte needclose; /* function needs to close upvalues when returning */ 163 | } FuncState; 164 | 165 | 166 | LUAI_FUNC int luaY_nvarstack (FuncState *fs); 167 | LUAI_FUNC LClosure *luaY_parser (lua_State *L, ZIO *z, Mbuffer *buff, 168 | Dyndata *dyd, const char *name, int firstchar); 169 | 170 | 171 | #endif 172 | -------------------------------------------------------------------------------- /externals/lua/src/lprefix.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lprefix.h $ 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 | -------------------------------------------------------------------------------- /externals/lua/src/lstring.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lstring.c $ 3 | ** String table (keeps all strings handled by Lua) 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #define lstring_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 "lmem.h" 20 | #include "lobject.h" 21 | #include "lstate.h" 22 | #include "lstring.h" 23 | 24 | 25 | /* 26 | ** Maximum size for string table. 27 | */ 28 | #define MAXSTRTB cast_int(luaM_limitN(MAX_INT, TString*)) 29 | 30 | 31 | /* 32 | ** equality for long strings 33 | */ 34 | int luaS_eqlngstr (TString *a, TString *b) { 35 | size_t len = a->u.lnglen; 36 | lua_assert(a->tt == LUA_VLNGSTR && b->tt == LUA_VLNGSTR); 37 | return (a == b) || /* same instance or... */ 38 | ((len == b->u.lnglen) && /* equal length and ... */ 39 | (memcmp(getstr(a), getstr(b), len) == 0)); /* equal contents */ 40 | } 41 | 42 | 43 | unsigned int luaS_hash (const char *str, size_t l, unsigned int seed) { 44 | unsigned int h = seed ^ cast_uint(l); 45 | for (; l > 0; l--) 46 | h ^= ((h<<5) + (h>>2) + cast_byte(str[l - 1])); 47 | return h; 48 | } 49 | 50 | 51 | unsigned int luaS_hashlongstr (TString *ts) { 52 | lua_assert(ts->tt == LUA_VLNGSTR); 53 | if (ts->extra == 0) { /* no hash? */ 54 | size_t len = ts->u.lnglen; 55 | ts->hash = luaS_hash(getstr(ts), len, ts->hash); 56 | ts->extra = 1; /* now it has its hash */ 57 | } 58 | return ts->hash; 59 | } 60 | 61 | 62 | static void tablerehash (TString **vect, int osize, int nsize) { 63 | int i; 64 | for (i = osize; i < nsize; i++) /* clear new elements */ 65 | vect[i] = NULL; 66 | for (i = 0; i < osize; i++) { /* rehash old part of the array */ 67 | TString *p = vect[i]; 68 | vect[i] = NULL; 69 | while (p) { /* for each string in the list */ 70 | TString *hnext = p->u.hnext; /* save next */ 71 | unsigned int h = lmod(p->hash, nsize); /* new position */ 72 | p->u.hnext = vect[h]; /* chain it into array */ 73 | vect[h] = p; 74 | p = hnext; 75 | } 76 | } 77 | } 78 | 79 | 80 | /* 81 | ** Resize the string table. If allocation fails, keep the current size. 82 | ** (This can degrade performance, but any non-zero size should work 83 | ** correctly.) 84 | */ 85 | void luaS_resize (lua_State *L, int nsize) { 86 | stringtable *tb = &G(L)->strt; 87 | int osize = tb->size; 88 | TString **newvect; 89 | if (nsize < osize) /* shrinking table? */ 90 | tablerehash(tb->hash, osize, nsize); /* depopulate shrinking part */ 91 | newvect = luaM_reallocvector(L, tb->hash, osize, nsize, TString*); 92 | if (l_unlikely(newvect == NULL)) { /* reallocation failed? */ 93 | if (nsize < osize) /* was it shrinking table? */ 94 | tablerehash(tb->hash, nsize, osize); /* restore to original size */ 95 | /* leave table as it was */ 96 | } 97 | else { /* allocation succeeded */ 98 | tb->hash = newvect; 99 | tb->size = nsize; 100 | if (nsize > osize) 101 | tablerehash(newvect, osize, nsize); /* rehash for new size */ 102 | } 103 | } 104 | 105 | 106 | /* 107 | ** Clear API string cache. (Entries cannot be empty, so fill them with 108 | ** a non-collectable string.) 109 | */ 110 | void luaS_clearcache (global_State *g) { 111 | int i, j; 112 | for (i = 0; i < STRCACHE_N; i++) 113 | for (j = 0; j < STRCACHE_M; j++) { 114 | if (iswhite(g->strcache[i][j])) /* will entry be collected? */ 115 | g->strcache[i][j] = g->memerrmsg; /* replace it with something fixed */ 116 | } 117 | } 118 | 119 | 120 | /* 121 | ** Initialize the string table and the string cache 122 | */ 123 | void luaS_init (lua_State *L) { 124 | global_State *g = G(L); 125 | int i, j; 126 | stringtable *tb = &G(L)->strt; 127 | tb->hash = luaM_newvector(L, MINSTRTABSIZE, TString*); 128 | tablerehash(tb->hash, 0, MINSTRTABSIZE); /* clear array */ 129 | tb->size = MINSTRTABSIZE; 130 | /* pre-create memory-error message */ 131 | g->memerrmsg = luaS_newliteral(L, MEMERRMSG); 132 | luaC_fix(L, obj2gco(g->memerrmsg)); /* it should never be collected */ 133 | for (i = 0; i < STRCACHE_N; i++) /* fill cache with valid strings */ 134 | for (j = 0; j < STRCACHE_M; j++) 135 | g->strcache[i][j] = g->memerrmsg; 136 | } 137 | 138 | 139 | 140 | /* 141 | ** creates a new string object 142 | */ 143 | static TString *createstrobj (lua_State *L, size_t l, int tag, unsigned int h) { 144 | TString *ts; 145 | GCObject *o; 146 | size_t totalsize; /* total size of TString object */ 147 | totalsize = sizelstring(l); 148 | o = luaC_newobj(L, tag, totalsize); 149 | ts = gco2ts(o); 150 | ts->hash = h; 151 | ts->extra = 0; 152 | getstr(ts)[l] = '\0'; /* ending 0 */ 153 | return ts; 154 | } 155 | 156 | 157 | TString *luaS_createlngstrobj (lua_State *L, size_t l) { 158 | TString *ts = createstrobj(L, l, LUA_VLNGSTR, G(L)->seed); 159 | ts->u.lnglen = l; 160 | return ts; 161 | } 162 | 163 | 164 | void luaS_remove (lua_State *L, TString *ts) { 165 | stringtable *tb = &G(L)->strt; 166 | TString **p = &tb->hash[lmod(ts->hash, tb->size)]; 167 | while (*p != ts) /* find previous element */ 168 | p = &(*p)->u.hnext; 169 | *p = (*p)->u.hnext; /* remove element from its list */ 170 | tb->nuse--; 171 | } 172 | 173 | 174 | static void growstrtab (lua_State *L, stringtable *tb) { 175 | if (l_unlikely(tb->nuse == MAX_INT)) { /* too many strings? */ 176 | luaC_fullgc(L, 1); /* try to free some... */ 177 | if (tb->nuse == MAX_INT) /* still too many? */ 178 | luaM_error(L); /* cannot even create a message... */ 179 | } 180 | if (tb->size <= MAXSTRTB / 2) /* can grow string table? */ 181 | luaS_resize(L, tb->size * 2); 182 | } 183 | 184 | 185 | /* 186 | ** Checks whether short string exists and reuses it or creates a new one. 187 | */ 188 | static TString *internshrstr (lua_State *L, const char *str, size_t l) { 189 | TString *ts; 190 | global_State *g = G(L); 191 | stringtable *tb = &g->strt; 192 | unsigned int h = luaS_hash(str, l, g->seed); 193 | TString **list = &tb->hash[lmod(h, tb->size)]; 194 | lua_assert(str != NULL); /* otherwise 'memcmp'/'memcpy' are undefined */ 195 | for (ts = *list; ts != NULL; ts = ts->u.hnext) { 196 | if (l == ts->shrlen && (memcmp(str, getstr(ts), l * sizeof(char)) == 0)) { 197 | /* found! */ 198 | if (isdead(g, ts)) /* dead (but not collected yet)? */ 199 | changewhite(ts); /* resurrect it */ 200 | return ts; 201 | } 202 | } 203 | /* else must create a new string */ 204 | if (tb->nuse >= tb->size) { /* need to grow string table? */ 205 | growstrtab(L, tb); 206 | list = &tb->hash[lmod(h, tb->size)]; /* rehash with new size */ 207 | } 208 | ts = createstrobj(L, l, LUA_VSHRSTR, h); 209 | memcpy(getstr(ts), str, l * sizeof(char)); 210 | ts->shrlen = cast_byte(l); 211 | ts->u.hnext = *list; 212 | *list = ts; 213 | tb->nuse++; 214 | return ts; 215 | } 216 | 217 | 218 | /* 219 | ** new string (with explicit length) 220 | */ 221 | TString *luaS_newlstr (lua_State *L, const char *str, size_t l) { 222 | if (l <= LUAI_MAXSHORTLEN) /* short string? */ 223 | return internshrstr(L, str, l); 224 | else { 225 | TString *ts; 226 | if (l_unlikely(l >= (MAX_SIZE - sizeof(TString))/sizeof(char))) 227 | luaM_toobig(L); 228 | ts = luaS_createlngstrobj(L, l); 229 | memcpy(getstr(ts), str, l * sizeof(char)); 230 | return ts; 231 | } 232 | } 233 | 234 | 235 | /* 236 | ** Create or reuse a zero-terminated string, first checking in the 237 | ** cache (using the string address as a key). The cache can contain 238 | ** only zero-terminated strings, so it is safe to use 'strcmp' to 239 | ** check hits. 240 | */ 241 | TString *luaS_new (lua_State *L, const char *str) { 242 | unsigned int i = point2uint(str) % STRCACHE_N; /* hash */ 243 | int j; 244 | TString **p = G(L)->strcache[i]; 245 | for (j = 0; j < STRCACHE_M; j++) { 246 | if (strcmp(str, getstr(p[j])) == 0) /* hit? */ 247 | return p[j]; /* that is it */ 248 | } 249 | /* normal route */ 250 | for (j = STRCACHE_M - 1; j > 0; j--) 251 | p[j] = p[j - 1]; /* move out last element */ 252 | /* new element is first in the list */ 253 | p[0] = luaS_newlstr(L, str, strlen(str)); 254 | return p[0]; 255 | } 256 | 257 | 258 | Udata *luaS_newudata (lua_State *L, size_t s, int nuvalue) { 259 | Udata *u; 260 | int i; 261 | GCObject *o; 262 | if (l_unlikely(s > MAX_SIZE - udatamemoffset(nuvalue))) 263 | luaM_toobig(L); 264 | o = luaC_newobj(L, LUA_VUSERDATA, sizeudata(nuvalue, s)); 265 | u = gco2u(o); 266 | u->len = s; 267 | u->nuvalue = nuvalue; 268 | u->metatable = NULL; 269 | for (i = 0; i < nuvalue; i++) 270 | setnilvalue(&u->uv[i].uv); 271 | return u; 272 | } 273 | 274 | -------------------------------------------------------------------------------- /externals/lua/src/lstring.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lstring.h $ 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 | /* 16 | ** Memory-allocation error message must be preallocated (it cannot 17 | ** be created after memory is exhausted) 18 | */ 19 | #define MEMERRMSG "not enough memory" 20 | 21 | 22 | /* 23 | ** Size of a TString: Size of the header plus space for the string 24 | ** itself (including final '\0'). 25 | */ 26 | #define sizelstring(l) (offsetof(TString, contents) + ((l) + 1) * sizeof(char)) 27 | 28 | #define luaS_newliteral(L, s) (luaS_newlstr(L, "" s, \ 29 | (sizeof(s)/sizeof(char))-1)) 30 | 31 | 32 | /* 33 | ** test whether a string is a reserved word 34 | */ 35 | #define isreserved(s) ((s)->tt == LUA_VSHRSTR && (s)->extra > 0) 36 | 37 | 38 | /* 39 | ** equality for short strings, which are always internalized 40 | */ 41 | #define eqshrstr(a,b) check_exp((a)->tt == LUA_VSHRSTR, (a) == (b)) 42 | 43 | 44 | LUAI_FUNC unsigned int luaS_hash (const char *str, size_t l, unsigned int seed); 45 | LUAI_FUNC unsigned int luaS_hashlongstr (TString *ts); 46 | LUAI_FUNC int luaS_eqlngstr (TString *a, TString *b); 47 | LUAI_FUNC void luaS_resize (lua_State *L, int newsize); 48 | LUAI_FUNC void luaS_clearcache (global_State *g); 49 | LUAI_FUNC void luaS_init (lua_State *L); 50 | LUAI_FUNC void luaS_remove (lua_State *L, TString *ts); 51 | LUAI_FUNC Udata *luaS_newudata (lua_State *L, size_t s, int nuvalue); 52 | LUAI_FUNC TString *luaS_newlstr (lua_State *L, const char *str, size_t l); 53 | LUAI_FUNC TString *luaS_new (lua_State *L, const char *str); 54 | LUAI_FUNC TString *luaS_createlngstrobj (lua_State *L, size_t l); 55 | 56 | 57 | #endif 58 | -------------------------------------------------------------------------------- /externals/lua/src/ltable.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: ltable.h $ 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)->u.next) 16 | 17 | 18 | /* 19 | ** Clear all bits of fast-access metamethods, which means that the table 20 | ** may have any of these metamethods. (First access that fails after the 21 | ** clearing will set the bit again.) 22 | */ 23 | #define invalidateTMcache(t) ((t)->flags &= ~maskflags) 24 | 25 | 26 | /* true when 't' is using 'dummynode' as its hash part */ 27 | #define isdummy(t) ((t)->lastfree == NULL) 28 | 29 | 30 | /* allocated size for hash nodes */ 31 | #define allocsizenode(t) (isdummy(t) ? 0 : sizenode(t)) 32 | 33 | 34 | /* returns the Node, given the value of a table entry */ 35 | #define nodefromval(v) cast(Node *, (v)) 36 | 37 | 38 | LUAI_FUNC const TValue *luaH_getint (Table *t, lua_Integer key); 39 | LUAI_FUNC void luaH_setint (lua_State *L, Table *t, lua_Integer key, 40 | TValue *value); 41 | LUAI_FUNC const TValue *luaH_getshortstr (Table *t, TString *key); 42 | LUAI_FUNC const TValue *luaH_getstr (Table *t, TString *key); 43 | LUAI_FUNC const TValue *luaH_get (Table *t, const TValue *key); 44 | LUAI_FUNC void luaH_newkey (lua_State *L, Table *t, const TValue *key, 45 | TValue *value); 46 | LUAI_FUNC void luaH_set (lua_State *L, Table *t, const TValue *key, 47 | TValue *value); 48 | LUAI_FUNC void luaH_finishset (lua_State *L, Table *t, const TValue *key, 49 | const TValue *slot, TValue *value); 50 | LUAI_FUNC Table *luaH_new (lua_State *L); 51 | LUAI_FUNC void luaH_resize (lua_State *L, Table *t, unsigned int nasize, 52 | unsigned int nhsize); 53 | LUAI_FUNC void luaH_resizearray (lua_State *L, Table *t, unsigned int nasize); 54 | LUAI_FUNC void luaH_free (lua_State *L, Table *t); 55 | LUAI_FUNC int luaH_next (lua_State *L, Table *t, StkId key); 56 | LUAI_FUNC lua_Unsigned luaH_getn (Table *t); 57 | LUAI_FUNC unsigned int luaH_realasize (const 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 | -------------------------------------------------------------------------------- /externals/lua/src/ltm.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: ltm.h $ 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_CLOSE, 44 | TM_N /* number of elements in the enum */ 45 | } TMS; 46 | 47 | 48 | /* 49 | ** Mask with 1 in all fast-access methods. A 1 in any of these bits 50 | ** in the flag of a (meta)table means the metatable does not have the 51 | ** corresponding metamethod field. (Bit 7 of the flag is used for 52 | ** 'isrealasize'.) 53 | */ 54 | #define maskflags (~(~0u << (TM_EQ + 1))) 55 | 56 | 57 | /* 58 | ** Test whether there is no tagmethod. 59 | ** (Because tagmethods use raw accesses, the result may be an "empty" nil.) 60 | */ 61 | #define notm(tm) ttisnil(tm) 62 | 63 | 64 | #define gfasttm(g,et,e) ((et) == NULL ? NULL : \ 65 | ((et)->flags & (1u<<(e))) ? NULL : luaT_gettm(et, e, (g)->tmname[e])) 66 | 67 | #define fasttm(l,et,e) gfasttm(G(l), et, e) 68 | 69 | #define ttypename(x) luaT_typenames_[(x) + 1] 70 | 71 | LUAI_DDEC(const char *const luaT_typenames_[LUA_TOTALTYPES];) 72 | 73 | 74 | LUAI_FUNC const char *luaT_objtypename (lua_State *L, const TValue *o); 75 | 76 | LUAI_FUNC const TValue *luaT_gettm (Table *events, TMS event, TString *ename); 77 | LUAI_FUNC const TValue *luaT_gettmbyobj (lua_State *L, const TValue *o, 78 | TMS event); 79 | LUAI_FUNC void luaT_init (lua_State *L); 80 | 81 | LUAI_FUNC void luaT_callTM (lua_State *L, const TValue *f, const TValue *p1, 82 | const TValue *p2, const TValue *p3); 83 | LUAI_FUNC void luaT_callTMres (lua_State *L, const TValue *f, 84 | const TValue *p1, const TValue *p2, StkId p3); 85 | LUAI_FUNC void luaT_trybinTM (lua_State *L, const TValue *p1, const TValue *p2, 86 | StkId res, TMS event); 87 | LUAI_FUNC void luaT_tryconcatTM (lua_State *L); 88 | LUAI_FUNC void luaT_trybinassocTM (lua_State *L, const TValue *p1, 89 | const TValue *p2, int inv, StkId res, TMS event); 90 | LUAI_FUNC void luaT_trybiniTM (lua_State *L, const TValue *p1, lua_Integer i2, 91 | int inv, StkId res, TMS event); 92 | LUAI_FUNC int luaT_callorderTM (lua_State *L, const TValue *p1, 93 | const TValue *p2, TMS event); 94 | LUAI_FUNC int luaT_callorderiTM (lua_State *L, const TValue *p1, int v2, 95 | int inv, int isfloat, TMS event); 96 | 97 | LUAI_FUNC void luaT_adjustvarargs (lua_State *L, int nfixparams, 98 | struct CallInfo *ci, const Proto *p); 99 | LUAI_FUNC void luaT_getvarargs (lua_State *L, struct CallInfo *ci, 100 | StkId where, int wanted); 101 | 102 | 103 | #endif 104 | -------------------------------------------------------------------------------- /externals/lua/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 | -------------------------------------------------------------------------------- /externals/lua/src/lualib.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lualib.h $ 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_MATHLIBNAME "math" 39 | LUAMOD_API int (luaopen_math) (lua_State *L); 40 | 41 | #define LUA_DBLIBNAME "debug" 42 | LUAMOD_API int (luaopen_debug) (lua_State *L); 43 | 44 | #define LUA_LOADLIBNAME "package" 45 | LUAMOD_API int (luaopen_package) (lua_State *L); 46 | 47 | 48 | /* open all previous libraries */ 49 | LUALIB_API void (luaL_openlibs) (lua_State *L); 50 | 51 | 52 | #endif 53 | -------------------------------------------------------------------------------- /externals/lua/src/lundump.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lundump.h $ 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 | /* 22 | ** Encode major-minor version in one byte, one nibble for each 23 | */ 24 | #define MYINT(s) (s[0]-'0') /* assume one-digit numerals */ 25 | #define LUAC_VERSION (MYINT(LUA_VERSION_MAJOR)*16+MYINT(LUA_VERSION_MINOR)) 26 | 27 | #define LUAC_FORMAT 0 /* this is the official format */ 28 | 29 | /* load one chunk; from lundump.c */ 30 | LUAI_FUNC LClosure* luaU_undump (lua_State* L, ZIO* Z, const char* name); 31 | 32 | /* dump one chunk; from ldump.c */ 33 | LUAI_FUNC int luaU_dump (lua_State* L, const Proto* f, lua_Writer w, 34 | void* data, int strip); 35 | 36 | #endif 37 | -------------------------------------------------------------------------------- /externals/lua/src/lvm.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lvm.h $ 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 F2Ieq 37 | #endif 38 | 39 | 40 | /* 41 | ** Rounding modes for float->integer coercion 42 | */ 43 | typedef enum { 44 | F2Ieq, /* no rounding; accepts only integral values */ 45 | F2Ifloor, /* takes the floor of the number */ 46 | F2Iceil /* takes the ceil of the number */ 47 | } F2Imod; 48 | 49 | 50 | /* convert an object to a float (including string coercion) */ 51 | #define tonumber(o,n) \ 52 | (ttisfloat(o) ? (*(n) = fltvalue(o), 1) : luaV_tonumber_(o,n)) 53 | 54 | 55 | /* convert an object to a float (without string coercion) */ 56 | #define tonumberns(o,n) \ 57 | (ttisfloat(o) ? ((n) = fltvalue(o), 1) : \ 58 | (ttisinteger(o) ? ((n) = cast_num(ivalue(o)), 1) : 0)) 59 | 60 | 61 | /* convert an object to an integer (including string coercion) */ 62 | #define tointeger(o,i) \ 63 | (l_likely(ttisinteger(o)) ? (*(i) = ivalue(o), 1) \ 64 | : luaV_tointeger(o,i,LUA_FLOORN2I)) 65 | 66 | 67 | /* convert an object to an integer (without string coercion) */ 68 | #define tointegerns(o,i) \ 69 | (l_likely(ttisinteger(o)) ? (*(i) = ivalue(o), 1) \ 70 | : luaV_tointegerns(o,i,LUA_FLOORN2I)) 71 | 72 | 73 | #define intop(op,v1,v2) l_castU2S(l_castS2U(v1) op l_castS2U(v2)) 74 | 75 | #define luaV_rawequalobj(t1,t2) luaV_equalobj(NULL,t1,t2) 76 | 77 | 78 | /* 79 | ** fast track for 'gettable': if 't' is a table and 't[k]' is present, 80 | ** return 1 with 'slot' pointing to 't[k]' (position of final result). 81 | ** Otherwise, return 0 (meaning it will have to check metamethod) 82 | ** with 'slot' pointing to an empty 't[k]' (if 't' is a table) or NULL 83 | ** (otherwise). 'f' is the raw get function to use. 84 | */ 85 | #define luaV_fastget(L,t,k,slot,f) \ 86 | (!ttistable(t) \ 87 | ? (slot = NULL, 0) /* not a table; 'slot' is NULL and result is 0 */ \ 88 | : (slot = f(hvalue(t), k), /* else, do raw access */ \ 89 | !isempty(slot))) /* result not empty? */ 90 | 91 | 92 | /* 93 | ** Special case of 'luaV_fastget' for integers, inlining the fast case 94 | ** of 'luaH_getint'. 95 | */ 96 | #define luaV_fastgeti(L,t,k,slot) \ 97 | (!ttistable(t) \ 98 | ? (slot = NULL, 0) /* not a table; 'slot' is NULL and result is 0 */ \ 99 | : (slot = (l_castS2U(k) - 1u < hvalue(t)->alimit) \ 100 | ? &hvalue(t)->array[k - 1] : luaH_getint(hvalue(t), k), \ 101 | !isempty(slot))) /* result not empty? */ 102 | 103 | 104 | /* 105 | ** Finish a fast set operation (when fast get succeeds). In that case, 106 | ** 'slot' points to the place to put the value. 107 | */ 108 | #define luaV_finishfastset(L,t,slot,v) \ 109 | { setobj2t(L, cast(TValue *,slot), v); \ 110 | luaC_barrierback(L, gcvalue(t), v); } 111 | 112 | 113 | 114 | 115 | LUAI_FUNC int luaV_equalobj (lua_State *L, const TValue *t1, const TValue *t2); 116 | LUAI_FUNC int luaV_lessthan (lua_State *L, const TValue *l, const TValue *r); 117 | LUAI_FUNC int luaV_lessequal (lua_State *L, const TValue *l, const TValue *r); 118 | LUAI_FUNC int luaV_tonumber_ (const TValue *obj, lua_Number *n); 119 | LUAI_FUNC int luaV_tointeger (const TValue *obj, lua_Integer *p, F2Imod mode); 120 | LUAI_FUNC int luaV_tointegerns (const TValue *obj, lua_Integer *p, 121 | F2Imod mode); 122 | LUAI_FUNC int luaV_flttointeger (lua_Number n, lua_Integer *p, F2Imod mode); 123 | LUAI_FUNC void luaV_finishget (lua_State *L, const TValue *t, TValue *key, 124 | StkId val, const TValue *slot); 125 | LUAI_FUNC void luaV_finishset (lua_State *L, const TValue *t, TValue *key, 126 | TValue *val, const TValue *slot); 127 | LUAI_FUNC void luaV_finishOp (lua_State *L); 128 | LUAI_FUNC void luaV_execute (lua_State *L, CallInfo *ci); 129 | LUAI_FUNC void luaV_concat (lua_State *L, int total); 130 | LUAI_FUNC lua_Integer luaV_idiv (lua_State *L, lua_Integer x, lua_Integer y); 131 | LUAI_FUNC lua_Integer luaV_mod (lua_State *L, lua_Integer x, lua_Integer y); 132 | LUAI_FUNC lua_Number luaV_modf (lua_State *L, lua_Number x, lua_Number y); 133 | LUAI_FUNC lua_Integer luaV_shiftl (lua_Integer x, lua_Integer y); 134 | LUAI_FUNC void luaV_objlen (lua_State *L, StkId ra, const TValue *rb); 135 | 136 | #endif 137 | -------------------------------------------------------------------------------- /externals/lua/src/lzio.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lzio.c $ 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 | -------------------------------------------------------------------------------- /externals/lua/src/lzio.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lzio.h $ 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 | -------------------------------------------------------------------------------- /externals/lua_version.txt: -------------------------------------------------------------------------------- 1 | 5.4.4 -------------------------------------------------------------------------------- /include/_version.h: -------------------------------------------------------------------------------- 1 | #define FILEVER 1,0,0,0 2 | #define PRODUCTVER 1,0,0,0 3 | #define STRFILEVER "{major}.{minor}.{build}\0" 4 | #define STRPRODUCTVER "{major}.{minor}.{build}\0" 5 | -------------------------------------------------------------------------------- /include/bus.h: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * @file bus.h 4 | * @author Lavrentiy Ivanov (ookami@mail.ru) 5 | * @date 22.09.2014 6 | * @copyright Copyright 2014 Lavrentiy Ivanov. All rights reserved 7 | * @license This project is released under the BSD 2-Clause license. 8 | * @brief Set of PIN object methods 9 | * 10 | */ 11 | 12 | #pragma once 13 | 14 | 15 | int lua_set_bus ( lua_State* L ); 16 | int lua_get_bus ( lua_State* L ); 17 | -------------------------------------------------------------------------------- /include/cbind.h: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * @file c_bind.h 4 | * @author Lavrentiy Ivanov (ookami@mail.ru) 5 | * @date 22.09.2014 6 | * @brief The main C wrapper of official API 7 | * @copyright Copyright 2014 Lavrentiy Ivanov. All rights reserved 8 | * @license This project is released under the BSD 2-Clause license. 9 | * 10 | */ 11 | 12 | #pragma once 13 | 14 | #include 15 | 16 | /* DEBUG */ 17 | 18 | void console_alloc ( const char* title ); 19 | 20 | /* DEVICE */ 21 | 22 | void set_logic_type ( IDSIMMODEL* model, LOGIC_TYPE type ); 23 | const char* logic_type_to_string ( LOGIC_TYPE type ); 24 | bool get_bool_param ( IDSIMMODEL* model, char* field_name ); 25 | bool set_vdm_handler ( IDSIMMODEL* model ); 26 | bool vsm_register ( ILICENCESERVER* ils ); 27 | char* get_device_id ( IDSIMMODEL* model ); 28 | char* get_string_param ( IDSIMMODEL* model, char* field_name ); 29 | double get_num_param ( IDSIMMODEL* model, char* field_name ); 30 | int32_t get_hex_param ( IDSIMMODEL* model, char* field_name ); 31 | int64_t get_init_param ( IDSIMMODEL* model, char* field_name ); 32 | void load_image ( IDSIMMODEL* model, char* filename, uint8_t* buffer, uint32_t buffer_size ); 33 | void systime ( IDSIMMODEL* model, ABSTIME* at ); 34 | 35 | /* LOGGING */ 36 | 37 | void print_error ( IDSIMMODEL* model, const char* format, ... ); 38 | void print_info ( IDSIMMODEL* model, const char* format, ... ); 39 | void print_message ( IDSIMMODEL* model, const char* format, ... ); 40 | void print_warning ( IDSIMMODEL* model, const char* format, ... ); 41 | void set_callback ( IDSIMMODEL* model, RELTIME picotime, EVENTID id ); 42 | void set_pin_state ( IDSIMMODEL* model, VSM_PIN pin, STATE state ); 43 | 44 | /* POPUP */ 45 | 46 | IDEBUGPOPUP* create_debug_popup ( IDSIMMODEL* model, const char* title, const int32_t id ); 47 | IDEBUGPOPUP* create_source_popup ( IDSIMMODEL* model, const char* title, const int32_t id ); 48 | IDEBUGPOPUP* create_status_popup ( IDSIMMODEL* model, const char* title, const int32_t id ); 49 | IDEBUGPOPUP* create_var_popup ( IDSIMMODEL* model, const char* title, const int32_t id ); 50 | IMEMORYPOPUP* create_memory_popup ( IDSIMMODEL* model, const char* title, const int32_t id ); 51 | IPOPUP* create_popup ( IDSIMMODEL* model, CREATEPOPUPSTRUCT* cps ); 52 | bool add_source_file ( ISOURCEPOPUP* popup, char* filename, bool lowlevel ); 53 | void delete_popup ( IDSIMMODEL* model, POPUPID id ); 54 | void dump_to_debug_popup ( IDEBUGPOPUP* popup, const uint8_t* buf, uint32_t offset, uint32_t size ); 55 | void print_to_debug_popup ( IDEBUGPOPUP* popup, const char* message ); 56 | void repaint_memory_popup ( IMEMORYPOPUP* popup ); 57 | void set_memory_popup ( IMEMORYPOPUP* popup, uint32_t offset, void* buffer, size_t size ); 58 | void set_pc_address ( ISOURCEPOPUP* popup, uint32_t address ); 59 | 60 | /* PINS */ 61 | 62 | __INLINE__ bool iscontention ( STATE s ); 63 | __INLINE__ bool isdefined ( STATE s ); 64 | __INLINE__ bool isfloating ( STATE s ); 65 | __INLINE__ bool ishigh ( STATE s ); 66 | __INLINE__ bool ishighlow ( STATE s ); 67 | __INLINE__ bool islow ( STATE s ); 68 | __INLINE__ INT polarity ( STATE s ); 69 | __INLINE__ INT strength ( STATE s ); 70 | 71 | bool is_pin_active ( IDSIMPIN* pin ); 72 | bool is_pin_inactive ( IDSIMPIN* pin ); 73 | bool is_pin_inverted ( IDSIMPIN* pin ); 74 | bool is_pin_posedge ( IDSIMPIN* pin ); 75 | bool is_pin_negedge ( IDSIMPIN* pin ); 76 | bool is_pin_edge ( IDSIMPIN* pin ); 77 | bool is_pin_floating ( IDSIMPIN* pin ); 78 | bool is_pin_high ( IDSIMPIN* pin ); 79 | bool is_pin_low ( IDSIMPIN* pin ); 80 | bool is_pin_steady ( IDSIMPIN* pin ); 81 | 82 | IDSIMPIN* get_pin ( IDSIMMODEL* model, char* pin_name ); 83 | STATE get_pin_state ( IDSIMPIN* pin ); 84 | const char* state_to_string ( STATE s ); 85 | int32_t get_pin_bool ( VSM_PIN pin ); 86 | void set_pin_bool ( IDSIMMODEL* model, VSM_PIN pin, bool level ); 87 | void toggle_pin_state ( IDSIMMODEL* model, VSM_PIN pin ); 88 | -------------------------------------------------------------------------------- /include/defines.h: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * @file defines.h 4 | * @author Lavrentiy Ivanov (ookami@mail.ru) 5 | * @date 22.09.2014 6 | * @copyright Copyright 2014 Lavrentiy Ivanov. All rights reserved 7 | * @license This project is released under the BSD 2-Clause license. 8 | * 9 | */ 10 | 11 | 12 | #ifndef VSMAPI_DEFINES 13 | #define VSMAPI_DEFINES 14 | 15 | #include 16 | 17 | typedef uint32_t COLOUR; 18 | typedef uint32_t MESSAGE; 19 | 20 | #define IDSIMPIN IDSIMPIN1 21 | //#define IDSIMPIN IDSIMPIN2 22 | 23 | typedef uint32_t ADDRESS; 24 | #define WATCHITEM_NAME_SIZE 128 25 | #define WATCHITEM_ADDR_SIZE 32 26 | 27 | 28 | // Flags for controlling property visibility 29 | #define SHOW_ALL 0 30 | #define HIDE_KEYWORD 1 31 | #define HIDE_VALUE 2 32 | #define HIDE_ALL 3 33 | #define HIDE_NOMODIFY 4 34 | 35 | // Useful Colours: 36 | #define MAKECOLOUR(r,g,b) ((COLOUR)(((uint8_t)(r)|((uint16_t)((uint8_t)(g))<<8))|(((uint32_t)(uint8_t)(b))<<16))) 37 | #define BLACK MAKECOLOUR(0x00,0x00,0x00) 38 | #define BLUE MAKECOLOUR(0x00,0x00,0xC0) 39 | #define GREEN MAKECOLOUR(0x00,0xC0,0x00) 40 | #define CYAN MAKECOLOUR(0x00,0xC0,0xC0) 41 | #define RED MAKECOLOUR(0xC0,0x00,0x00) 42 | #define MAGENTA MAKECOLOUR(0xC0,0x00,0xC0) 43 | #define YELLOW MAKECOLOUR(0xC0,0xC0,0x00) 44 | #define WHITE MAKECOLOUR(0xC0,0xC0,0xC0) 45 | #define GREY MAKECOLOUR(0x80,0x80,0x80) 46 | #define DARKBLUE MAKECOLOUR(0x00,0x00,0x40) 47 | #define DARKGREEN MAKECOLOUR(0x00,0x40,0x00) 48 | #define DARKCYAN MAKECOLOUR(0x00,0x40,0x40) 49 | #define DARKRED MAKECOLOUR(0x40,0x00,0x00) 50 | #define DARKMAGENTA MAKECOLOUR(0x40,0x00,0x40) 51 | #define DARKYELLOW MAKECOLOUR(0x40,0x40,0x00) 52 | #define DARKGREY MAKECOLOUR(0x40,0x40,0x40) 53 | #define MIDBLUE MAKECOLOUR(0x00,0x00,0x80) 54 | #define MIDGREEN MAKECOLOUR(0x00,0x80,0x00) 55 | #define MIDCYAN MAKECOLOUR(0x00,0x80,0x80) 56 | #define MIDRED MAKECOLOUR(0x80,0x00,0x00) 57 | #define MIDMAGENTA MAKECOLOUR(0x80,0x00,0x80) 58 | #define MIDYELLOW MAKECOLOUR(0x80,0x80,0x00) 59 | #define MIDGREY MAKECOLOUR(0x80,0x80,0x80) 60 | #define LIGHTBLUE MAKECOLOUR(0x00,0x00,0xC0) 61 | #define LIGHTGREEN MAKECOLOUR(0x00,0xC0,0x00) 62 | #define LIGHTCYAN MAKECOLOUR(0x00,0xC0,0xC0) 63 | #define LIGHTRED MAKECOLOUR(0xC0,0x00,0x00) 64 | #define LIGHTMAGENTA MAKECOLOUR(0xC0,0x00,0xC0) 65 | #define LIGHTYELLOW MAKECOLOUR(0xC0,0xC0,0x00) 66 | #define LIGHTGREY MAKECOLOUR(0xC0,0xC0,0xC0) 67 | #define BRIGHTBLUE MAKECOLOUR(0x00,0x00,0xFF) 68 | #define BRIGHTGREEN MAKECOLOUR(0x00,0xFF,0x00) 69 | #define BRIGHTCYAN MAKECOLOUR(0x00,0xFF,0xFF) 70 | #define BRIGHTRED MAKECOLOUR(0xFF,0x00,0x00) 71 | #define BRIGHTMAGENTA MAKECOLOUR(0xFF,0x00,0xFF) 72 | #define BRIGHTYELLOW MAKECOLOUR(0xFF,0xFF,0x00) 73 | #define BRIGHTWHITE MAKECOLOUR(0xFF,0xFF,0xFF) 74 | 75 | #define INVISIBLE -1 76 | #define NOCOLOUR -1 77 | 78 | 79 | 80 | // Text justifications: 81 | #define TXJ_LEFT 0 82 | #define TXJ_RIGHT 1 83 | #define TXJ_CENTRE 2 84 | #define TXJ_BOTTOM 0 85 | #define TXJ_TOP 4 86 | #define TXJ_MIDDLE 8 87 | 88 | // Handles for graphics and text styles 89 | typedef void* HGFXSTYLE; 90 | typedef void* HTEXTSTYLE; 91 | 92 | // Pop-up window interfaces. 93 | // Handles, types, etc. for pop-up windows: 94 | typedef void IPOPUP; 95 | typedef uint32_t POPUPID; 96 | typedef uint32_t INSTANCEID; 97 | 98 | typedef double REALTIME; 99 | typedef LONGLONG ABSTIME; 100 | //typedef const ABSTIME &CREFABSTIME; 101 | typedef LONGLONG RELTIME; 102 | //typedef const RELTIME &CREFRELTIME; 103 | 104 | // Time Conversion Macros 105 | #define DSIMTICK 1e-12 106 | 107 | // Maximum bits in bus: 108 | #define MAXBUSBITS 32 109 | 110 | typedef double SPICEFREQ; 111 | 112 | typedef int64_t ACTIVESTATE; 113 | 114 | // Pin drive flags 115 | #define DPF_INPUT 0x01 116 | #define DPF_OUTPUT 0x02 117 | #define DPF_BIDIR 0x03 118 | 119 | // State polarity bits: 120 | #define SP_UNDEFINED 0x00 // The undefined state. 121 | #define SP_LOW 0x01 // Polarity Low. 122 | #define SP_FLOAT 0x02 // Polarity Float (i.e. half volts). 123 | #define SP_HIGH 0x03 // Polarity High. 124 | #define SP_MASK 0x03 // Use to mask off polarity. 125 | 126 | // State strength bits: 127 | #define SS_FLOAT 0x00 // Strength Float. 128 | #define SS_DRIVEN 0x04 // Flag bit for driven state. 129 | #define SS_WEAK 0x04 // Strength Weak. 130 | #define SS_STRONG 0x0C // Strength Strong. 131 | #define SS_INJECT 0x14 // Strength for generators. 132 | #define SS_POWER 0x1C // Strength Power rail. 133 | #define SS_MASK 0x1C // Used to mask off strength. 134 | 135 | // State flag bits: 136 | #define SF_CONTENTION 0x20 // 137 | #define SF_MESSAGE 0x40 // Message associated with state (?) 138 | #define SF_MASK 0xE0 // Use to mask off flags. 139 | 140 | typedef long EVENTID; 141 | #define EID_BREAKPOINT 0x8000000 142 | 143 | // Pin types: 144 | typedef int32_t SPICENODE; 145 | typedef void* DSIMNODE; 146 | 147 | #endif 148 | -------------------------------------------------------------------------------- /include/enums.h: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * @file enums.h 4 | * @author Lavrentiy Ivanov (ookami@mail.ru) 5 | * @date 22.09.2014 6 | * @copyright Copyright 2014 Lavrentiy Ivanov. All rights reserved 7 | * @license This project is released under the BSD 2-Clause license. 8 | * 9 | */ 10 | 11 | #ifndef VSMAPI_ENUMS 12 | #define VSMAPI_ENUMS 13 | #include 14 | 15 | typedef enum LOGIC_TYPE 16 | { 17 | TTL = 0, 18 | CMOS, 19 | I2L 20 | } LOGIC_TYPE; 21 | 22 | typedef enum POPUPTYPES 23 | { 24 | PWT_USER = 0, 25 | PWT_DEBUG = 1, 26 | PWT_STATUS = 2, 27 | PWT_MEMORY = 3, 28 | PWT_WATCH = 5, 29 | PWT_SOURCE = 4, 30 | PWT_VAR = 6 31 | } POPUPTYPES; 32 | 33 | // Flags for creating pop-up windows. The bottom 20 bits are reserved for use by VSM, 34 | // whilst the remaining top 12 bits are available for user pop-ups. 35 | typedef enum POPUPFLAGS 36 | { 37 | PWF_VISIBLE = 0x00000001, 38 | PWF_SIZEABLE = 0x00000002, 39 | PWF_LOCKPOSITION = 0x00000004, 40 | PWF_HIDEONANIMATE = 0x00000008, 41 | PWF_AUTOREFRESH = 0x00000010, 42 | PWF_WANTKEYBOARD = 0x00000020, 43 | PWF_ACTIVE = 0x00008000, 44 | PWF_INTERNAL = 0x80000000 //-V112 45 | } POPUPFLAGS; 46 | 47 | typedef enum ACTUATEFLAGS 48 | { 49 | ACF_LEFT = 0x00000001, 50 | ACF_RIGHT = 0x00000002, 51 | ACF_MIDDLE = 0x00000004, 52 | ACF_INC = 0x00010000, 53 | ACF_DEC = 0x00020000, 54 | ACF_TOGGLE = 0x00040000 55 | } ACTUATEFLAGS; 56 | 57 | // Simulator Run Control Modes 58 | typedef enum RUNMODES 59 | { 60 | RM_BATCH=-1, 61 | RM_START, 62 | RM_STOP, 63 | RM_SUSPEND, 64 | RM_ANIMATE, 65 | RM_STEPTIME, 66 | RM_STEPOVER, 67 | RM_STEPINTO, 68 | RM_STEPOUT, 69 | RM_STEPTO, 70 | RM_META, 71 | RM_DUMP 72 | } RUNMODES; 73 | 74 | typedef enum SPICEMODES 75 | { 76 | SPICETRAN=0x1, 77 | SPICEAC=0x2, 78 | SPICEDC=0x70, 79 | SPICEDCOP=0x10, 80 | SPICETRANOP=0x20, 81 | SPICEDCTRANCURVE=0x40, 82 | SPICEINITFLOAT=0x100, 83 | SPICEINITJCT=0x200, 84 | SPICEINITFIX=0x400, 85 | SPICEINITSMSIG=0x800, 86 | SPICEINITTRAN=0x1000, 87 | SPICEINITPRED=0x2000, 88 | SPICEUIC=0x10000l 89 | } SPICEMODES; 90 | 91 | typedef enum SPICEVARS 92 | { 93 | SPICETIME, 94 | SPICEOMEGA, 95 | SPICEDELTA, 96 | SPICEGMIN, 97 | SPICEDELMIN, 98 | SPICEMINBREAK, 99 | SPICESRCFACT, 100 | SPICEFINALTIME, 101 | // Conv Tolerances? 102 | } SPICEVARS; 103 | 104 | typedef enum STATE 105 | { 106 | UNDEFINED = 0, 107 | TSTATE = 1, 108 | FSTATE = -1, 109 | PLO = SS_POWER+SP_LOW, 110 | ILO = SS_INJECT+SP_LOW, ///< I2L logic low 111 | SLO = SS_STRONG+SP_LOW, 112 | WLO = SS_WEAK+SP_LOW, 113 | FLT = SS_FLOAT+SP_FLOAT, 114 | WHI = SS_WEAK+SP_HIGH, ///< I2L logic high 115 | SHI = SS_STRONG+SP_HIGH, 116 | IHI = SS_INJECT+SP_HIGH, 117 | PHI = SS_POWER+SP_HIGH, 118 | WUD = SS_WEAK+SP_UNDEFINED, 119 | SUD = SS_STRONG+SP_UNDEFINED 120 | } STATE; 121 | 122 | typedef enum ACTIVEDATATYPES 123 | { 124 | ADT_VOID=-1, 125 | ADT_REAL, 126 | ADT_BOOLEAN, 127 | ADT_INTEGER, 128 | ADT_STATE, 129 | ADT_PINVOLTAGE, 130 | ADT_PINSTATE, 131 | ADT_WIREINFO, 132 | ADT_SPICEDATA, 133 | ADT_DSIMDATA, 134 | ADT_USER=100 135 | } ACTIVEDATATYPES; 136 | 137 | typedef enum DSIMMODES 138 | { 139 | DSIMBOOT = 0x01, 140 | DSIMSETTLE = 0x02, 141 | DSIMNORMAL = 0x04, 142 | DSIMEND = 0x08 143 | } DSIMMODES; 144 | 145 | typedef enum DSIMVARS 146 | { 147 | DSIMTIMENOW=-1, 148 | DSIMTDSCALE 149 | } DSIMVARS; 150 | 151 | typedef enum DATATYPES 152 | { 153 | DT_VOID=-1, DT_STRING, DT_TEXT, DT_BYTE, DT_WORD, DT_DWORD, DT_QWORD, DT_IEEE_FLOAT, DT_IEEE_DOUBLE, DT_HTEC_FLOAT, DT_MCHP_FLOAT, DT_BIGENDIAN=0x8000 154 | } DATATYPES; 155 | 156 | typedef enum DISPFORMATS 157 | { 158 | DF_VOID=-1, DF_BINARY, DF_OCTAL, DF_HEXADECIMAL, DF_SIGNED, DF_UNSIGNED, DF_FLOAT, DF_TEXT 159 | } DISPFORMATS; 160 | #endif 161 | -------------------------------------------------------------------------------- /include/luabind.h: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * @file lua_bind.h 4 | * @author Lavrentiy Ivanov (ookami@mail.ru) 5 | * @date 22.09.2014 6 | * @copyright Copyright 2014 Lavrentiy Ivanov. All rights reserved 7 | * @license This project is released under the BSD 2-Clause license. 8 | * 9 | */ 10 | 11 | #ifndef LUA_BIND_H 12 | #define LUA_BIND_H 13 | #include 14 | 15 | typedef struct lua_bind_func 16 | { 17 | int ( *lua_c_api ) ( lua_State* ); 18 | const char* lua_func_name; 19 | int ( *args[16] ) ( lua_State*, int index ); 20 | } lua_bind_func; 21 | 22 | typedef struct lua_bind_var 23 | { 24 | const char* var_name; 25 | int64_t var_value; 26 | } lua_bind_var; 27 | 28 | #define PIN_NAME "name" 29 | #define PIN_NUM "number" 30 | #define PIN_OFF_TIME "off_time" 31 | #define PIN_ON_TIME "on_time" 32 | 33 | void lua_load_modules ( IDSIMMODEL* this ); 34 | bool load_device_script ( IDSIMMODEL* model, const char* function ); 35 | void register_functions ( IDSIMMODEL* model, lua_State* L ); 36 | 37 | static int lua_state_to_string ( lua_State* L ); 38 | static int lua_print_info ( lua_State* L ); 39 | static int lua_print_message ( lua_State* L ); 40 | static int lua_print_warning ( lua_State* L ); 41 | static int lua_print_error ( lua_State* L ); 42 | static int lua_set_callback ( lua_State* L ); 43 | static int lua_create_debug_popup ( lua_State* L ); 44 | static int lua_print_to_debug_popup ( lua_State* L ); 45 | static int lua_dump_to_debug_popup ( lua_State* L ); 46 | static int lua_create_memory_popup ( lua_State* L ); 47 | static int lua_create_source_popup ( lua_State* L ); 48 | static int lua_create_status_popup ( lua_State* L ); 49 | static int lua_create_var_popup ( lua_State* L ); 50 | static int lua_delete_popup ( lua_State* L ); 51 | static int lua_set_memory_popup ( lua_State* L ); 52 | static int lua_repaint_memory_popup ( lua_State* L ); 53 | static int lua_get_string_param ( lua_State* L ); 54 | static int lua_get_bool_param ( lua_State* L ); 55 | static int lua_get_num_param ( lua_State* L ); 56 | static int lua_get_hex_param ( lua_State* L ); 57 | static int lua_get_init_param ( lua_State* L ); 58 | static int lua_add_source_file ( lua_State* L ); 59 | 60 | static int lua_get_systime ( lua_State* L ); 61 | 62 | #endif 63 | -------------------------------------------------------------------------------- /include/pin.h: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * @file pin.h 4 | * @author Lavrentiy Ivanov (ookami@mail.ru) 5 | * @date 22.09.2014 6 | * @copyright Copyright 2014 Lavrentiy Ivanov. All rights reserved 7 | * @license This project is released under the BSD 2-Clause license. 8 | * 9 | */ 10 | 11 | #pragma once 12 | 13 | void register_pin_obj ( lua_State* L, int num, char* name ); 14 | static int pin_set_hi(lua_State* L); 15 | static int pin_set_lo(lua_State* L); 16 | static int pin_set_fl(lua_State* L); 17 | static int pin_toggle(lua_State* L); 18 | static int pin_set(lua_State* L); 19 | static int pin_get(lua_State* L); 20 | static int pin_is_hi(lua_State* L); 21 | static int pin_is_lo(lua_State* L); 22 | static int pin_is_fl(lua_State* L); 23 | static int pin_is_edge(lua_State* L); 24 | static int pin_is_pedge(lua_State* L); 25 | static int pin_is_nedge(lua_State* L); 26 | static int pin_is_steady(lua_State* L); 27 | static int pin_is_active(lua_State* L); 28 | static int pin_is_inactive(lua_State* L); 29 | static int pin_is_inverted(lua_State* L); 30 | static int pin_set_state(lua_State* L); 31 | static int pin_get_state(lua_State* L); 32 | -------------------------------------------------------------------------------- /include/text.h: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * @file pin.h 4 | * @author Lavrentiy Ivanov (ookami@mail.ru) 5 | * @date 22.09.2014 6 | * @copyright Copyright 2014 Lavrentiy Ivanov. All rights reserved 7 | * @license This project is released under the BSD 2-Clause license. 8 | * @brief All constant text messages in source code 9 | * 10 | */ 11 | 12 | #pragma once 13 | 14 | #define TEXT_NO_PIN_OBJECT_FOUND "No pin object found" 15 | #define TEXT_NO_BUS_FOUND "No bus specified" 16 | #define TEXT_BUS_HAS_NO_PINS "Bus has no pins" 17 | #define TEXT_VALUE_WONT_FIT_BUS "%d is larger than bus can fit (%d)" 18 | 19 | 20 | #define TEXT_PIN_FIELD "pin" 21 | #define TEXT_HI_FIELD "hi" 22 | #define TEXT_LO_FIELD "lo" 23 | #define TEXT_FL_FIELD "fl" 24 | #define TEXT_SET_FIELD "set" 25 | #define TEXT_GET_FIELD "get" 26 | #define TEXT_TOGGLE_FIELD "toggle" 27 | 28 | 29 | #define TEXT_IS_HI_FIELD "is_hi" 30 | #define TEXT_IS_LO_FIELD "is_lo" 31 | #define TEXT_IS_FL_FIELD "is_fl" 32 | #define TEXT_IS_EDGE_FIELD "is_edge" 33 | #define TEXT_IS_PEDGE_FIELD "is_pedge" 34 | #define TEXT_IS_NEDGE_FIELD "is_nedge" 35 | #define TEXT_IS_STEADY_FIELD "is_steady" 36 | #define TEXT_IS_ACTIVE_FIELD "is_active" 37 | #define TEXT_IS_INACTIVE_FIELD "is_inactive" 38 | #define TEXT_IS_INVERTED_FIELD "is_inverted" 39 | #define TEXT_SET_STATE_FIELD "set_state" 40 | #define TEXT_GET_STATE_FIELD "get_state" 41 | 42 | -------------------------------------------------------------------------------- /include/utils.h: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * @file utils.h 4 | * @author Lavrentiy Ivanov (ookami@mail.ru) 5 | * @date 22.09.2014 6 | * @copyright Copyright 2014 Lavrentiy Ivanov. All rights reserved 7 | * @license This project is released under the BSD 2-Clause license. 8 | * @brief Set of PIN object methods 9 | * 10 | */ 11 | 12 | #pragma once 13 | #include 14 | 15 | uint64_t rand64bits(); 16 | uint64_t xorshift ( IDSIMMODEL* this ); 17 | -------------------------------------------------------------------------------- /include/vdmapi.h: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * @file vdm_api.h 4 | * @author Lavrentiy Ivanov (ookami@mail.ru) 5 | * @date 22.09.2014 6 | * @copyright Copyright 2014 Lavrentiy Ivanov. All rights reserved 7 | * @license This project is released under the GPL 2 license. 8 | * 9 | */ 10 | 11 | #pragma once 12 | 13 | #include 14 | #include 15 | #include 16 | #include "vsmapi.h" 17 | #include "defines.h" 18 | #include "enums.h" 19 | #include "vsmclasses.h" 20 | 21 | // VDM Protocol command strcuture: 22 | typedef struct VDM_COMMAND 23 | { 24 | BYTE command; 25 | BYTE memspace; 26 | DWORD address; 27 | DWORD datalength; 28 | } VDM_COMMAND; 29 | 30 | 31 | -------------------------------------------------------------------------------- /include/version.h: -------------------------------------------------------------------------------- 1 | #define FILEVER 1,0,0,0 2 | #define PRODUCTVER 1,0,0,0 3 | #define STRFILEVER "0.6.214\0" 4 | #define STRPRODUCTVER "0.6.214\0" 5 | -------------------------------------------------------------------------------- /include/vsmapi.h: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * @file vsm_api.h 4 | * @author Lavrentiy Ivanov (ookami@mail.ru) 5 | * @date 22.09.2014 6 | * @copyright Copyright 2014 Lavrentiy Ivanov. All rights reserved 7 | * @license This project is released under the GPL 2 license. 8 | * 9 | */ 10 | #pragma once 11 | 12 | /////////////////////////////////////////////////////////// 13 | /// Several macros for compatibility between VC and GCC /// 14 | /////////////////////////////////////////////////////////// 15 | #ifdef __MINGW32__ 16 | #define __CDECL__ __cdecl 17 | #elif _MSC_VER 18 | #define __CDECL__ __cdecl 19 | #else 20 | #error "unsupported compiler" 21 | #endif 22 | 23 | #ifdef __MINGW32__ 24 | #define __CDECLP__(func) (__cdecl(func)) 25 | #elif _MSC_VER 26 | #define __CDECLP__(func) (__cdecl func) 27 | #else 28 | #error "unsupported compiler" 29 | #endif 30 | 31 | #ifdef __MINGW32__ 32 | #define __FASTCALL__ __attribute__((fastcall)) 33 | #elif _MSC_VER 34 | #define __FASTCALL__ __fastcall 35 | #else 36 | #error "unsupported compiler" 37 | #endif 38 | 39 | #ifdef __MINGW32__ 40 | #define __FASTCALLP__(func) (__attribute__((fastcall)) (func)) 41 | #elif _MSC_VER 42 | #define __FASTCALLP__(func) (__fastcall func) 43 | #else 44 | #error "unsupported compiler" 45 | #endif 46 | 47 | #ifdef __MINGW32__ 48 | #define __INLINE__ inline 49 | #elif _MSC_VER 50 | #define __INLINE__ __forceinline 51 | #else 52 | #error "unsupported compiler" 53 | #endif 54 | 55 | ////////////////////////////////////////////////////////////////// 56 | #define _CRT_SECURE_NO_WARNINGS 57 | #include 58 | #include 59 | #include 60 | #include 61 | #include 62 | #include 63 | #include 64 | #include 65 | 66 | #include 67 | #include 68 | #include 69 | 70 | #include 71 | #include 72 | #include 73 | #include 74 | #include 75 | #include 76 | #include 77 | #include 78 | #include 79 | #include 80 | #include 81 | #include 82 | 83 | #undef _WIN32_WINNT 84 | #define _WIN32_WINNT 0x0500 85 | #define VSM_API_VERSION 110 86 | #define model_key 0x00000000 87 | 88 | #ifndef MAX_PIN_NUMBER 89 | #define MAX_PIN_NUMBER 64 90 | #endif 91 | 92 | #define PRINT (print_info) 93 | #define WARNING (print_warning) 94 | 95 | #define LOGIC_HI (model->logic_high) 96 | #define LOGIC_LO (model->logic_low) 97 | #define LOGIC_FLT (model->logic_flt) 98 | 99 | #define LSTRING (&lua_isstring) 100 | #define LINT (&lua_isnumber) 101 | #define LUSER (&lua_islightuserdata) 102 | #define LTABLE (&lua_istable) 103 | #define LNONE (NULL) 104 | typedef struct calltrace 105 | { 106 | void *func_addr; 107 | UT_hash_handle hh; 108 | } calltrace; 109 | 110 | int32_t vasprintf(char **sptr, char *fmt, va_list argv); 111 | int32_t asprintf(char **sptr, char *fmt, ...); 112 | 113 | int32_t __FASTCALL__ 114 | vsm_isdigital(IDSIMMODEL *this, uint32_t edx, char *pinname); 115 | void __FASTCALL__ 116 | vsm_setup(IDSIMMODEL *this, uint32_t edx, IINSTANCE *instance, IDSIMCKT *dsim); 117 | void __FASTCALL__ 118 | vsm_runctrl(IDSIMMODEL *this, uint32_t edx, RUNMODES mode); 119 | void __FASTCALL__ 120 | vsm_actuate(IDSIMMODEL *this, uint32_t edx, REALTIME atime, ACTIVESTATE newstate); 121 | bool __FASTCALL__ 122 | vsm_indicate(IDSIMMODEL *this, uint32_t edx, REALTIME atime, ACTIVEDATA *newstate); 123 | void __FASTCALL__ 124 | vsm_simulate(IDSIMMODEL *this, uint32_t edx, ABSTIME atime, DSIMMODES mode); 125 | void __FASTCALL__ 126 | vsm_timer_callback(IDSIMMODEL *this, uint32_t edx, ABSTIME atime, EVENTID eventid); 127 | 128 | LRESULT __FASTCALL__ 129 | icpu_vdmhlr(ICPU *this, uint32_t edx, VDM_COMMAND *cmd, uint8_t *data); 130 | void __FASTCALL__ 131 | icpu_loaddata(ICPU *this, EDX, int32_t format, int32_t seg, ADDRESS address, uint8_t *data, int32_t numbytes); 132 | void __FASTCALL__ 133 | icpu_disassemble(ICPU *this, EDX, ADDRESS address, int32_t numbytes); 134 | bool __FASTCALL__ 135 | icpu_getvardata(ICPU *this, EDX, VARITEM *vip, VARDATA *vdp); 136 | 137 | struct SPICEDATA 138 | { 139 | uint32_t numtimepoints; 140 | uint32_t numpins; 141 | REALTIME *timepoints; 142 | double *nodedata; 143 | }; 144 | 145 | struct DSIMDATA 146 | { 147 | uint32_t numtimepoints; 148 | uint32_t numpins; 149 | ABSTIME *timepoints; 150 | STATE *nodedata; 151 | }; 152 | 153 | struct CREATEPOPUPSTRUCT 154 | { 155 | POPUPID id; 156 | POPUPTYPES type; 157 | char *caption; 158 | int32_t width, height; 159 | uint32_t flags; 160 | }; 161 | 162 | struct ACTIVEDATA 163 | { 164 | ACTIVEDATATYPES type; 165 | union 166 | { 167 | int32_t intval; 168 | double realval; 169 | STATE stateval; 170 | double wireinfo[2]; // Voltage and current 171 | SPICEDATA spicedata; 172 | DSIMDATA dsimdata; 173 | void *userinfo; // Pointer to user data //-V117 174 | }; 175 | }; 176 | 177 | struct VARITEM 178 | { 179 | char name[WATCHITEM_NAME_SIZE]; 180 | uint32_t loader, seg; 181 | ADDRESS address; 182 | DATATYPES type; 183 | DISPFORMATS format; 184 | uint32_t size; 185 | ADDRESS scope_begin; 186 | ADDRESS scope_end; 187 | }; 188 | 189 | // Variable Data structure 190 | struct VARDATA 191 | { 192 | char addr[WATCHITEM_ADDR_SIZE]; 193 | DATATYPES type; 194 | uint8_t *memory; 195 | uint32_t memsize; 196 | uint32_t offset; // from start of memory block. 197 | }; 198 | 199 | struct ILICENCESERVER 200 | { 201 | ILICENCESERVER_vtable *vtable; 202 | }; 203 | 204 | struct EVENT 205 | { 206 | EVENT_vtable *vtable; 207 | }; 208 | 209 | struct ICPU 210 | { 211 | ICPU_vtable *vtable; 212 | }; 213 | 214 | extern ICPU ICPU_DEVICE; 215 | 216 | struct IDSIMPIN2 217 | { 218 | IDSIMPIN2_vtable *vtable; 219 | }; 220 | 221 | struct IDSIMPIN1 222 | { 223 | IDSIMPIN1_vtable *vtable; 224 | }; 225 | 226 | struct IDSIMMODEL 227 | { 228 | IDSIMMODEL_vtable *vtable; 229 | 230 | /* Custom objects */ 231 | 232 | IINSTANCE *model_instance; 233 | IDSIMCKT *model_dsim; 234 | lua_State *luactx; 235 | VSM_PIN device_pins[MAX_PIN_NUMBER]; 236 | calltrace *trace; 237 | /* Emulated logic type */ 238 | LOGIC_TYPE ltype; 239 | int logic_high; 240 | int logic_low; 241 | int logic_flt; 242 | /* simulation flags */ 243 | bool safe_mode; 244 | bool timer_callback_declared; 245 | bool device_init_declared; 246 | bool device_simulate_declared; 247 | /**/ 248 | int popup_id; ///< Popup identificator. Should be unique per model 249 | /**/ 250 | uint64_t xorseed[2]; // XOR SHIFT random seed 251 | }; 252 | 253 | struct IBUSPIN 254 | { 255 | ICPU_vtable *vtable; 256 | }; 257 | 258 | struct IINSTANCE 259 | { 260 | IINSTANCE_vtable *vtable; 261 | }; 262 | 263 | struct IDSIMCKT 264 | { 265 | IDSIMCKT_vtable *vtable; 266 | }; 267 | 268 | struct IUSERPOPUP 269 | { 270 | IUSERPOPUP_vtable *vtable; 271 | }; 272 | 273 | struct IDEBUGPOPUP 274 | { 275 | IDEBUGPOPUP_vtable *vtable; 276 | }; 277 | 278 | struct IMEMORYPOPUP 279 | { 280 | IMEMORYPOPUP_vtable *vtable; 281 | }; 282 | 283 | struct ISTATUSPOPUP 284 | { 285 | ISTATUSPOPUP_vtable *vtable; 286 | }; 287 | 288 | struct ISOURCEPOPUP 289 | { 290 | ISOURCEPOPUP_vtable *vtable; 291 | }; 292 | 293 | struct IMSGHLR 294 | { 295 | IMSGHLR_vtable *vtable; 296 | }; 297 | 298 | 299 | -------------------------------------------------------------------------------- /include/vsmobj.h: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * @file vsmobj.h 4 | * @author Lavrentiy Ivanov (ookami@mail.ru) 5 | * @date 22.09.2014 6 | * @copyright Copyright 2014 Lavrentiy Ivanov. All rights reserved 7 | * @license This project is released under the GPL 2 license. 8 | * 9 | */ 10 | 11 | #pragma once 12 | 13 | void* lua_get_model_obj ( lua_State* L ); 14 | -------------------------------------------------------------------------------- /relgen.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | majorversion=0 3 | subvn=$(git rev-list --merges HEAD | wc -l) 4 | subsubvn=$(git shortlog | grep -E '^[ ]+\w+' | wc -l) 5 | sed -e "s/{major}/$majorversion/" -e "s/{minor}/$subvn/" -e "s/{build}/$subsubvn/" ../include/_version.h > ../include/version.h 6 | echo "0.115" -------------------------------------------------------------------------------- /src/Makefile: -------------------------------------------------------------------------------- 1 | RELEASE=`../relgen.sh` 2 | 3 | MAKE=make 4 | CC:= i686-w64-mingw32-cc 5 | AR:= i686-w64-mingw32-ar 6 | OBJCOPY:= objcopy 7 | STRIP:= strip 8 | WINRES:= windres 9 | 10 | LIBDIR=../dll 11 | 12 | MOD=modules 13 | DEV=device 14 | XXD=../tools/bin2source.exe 15 | LUAC=../tools/luac.exe 16 | OPENVSMLIB?=$(LIBDIR)/openvsm 17 | LUADIR=lua 18 | 19 | SRC:=vsmapi.c \ 20 | lua_pin.c \ 21 | lua_bus.c \ 22 | lua_vsmobj.c \ 23 | utils.c \ 24 | wincompat.c \ 25 | bindings/cbind.c \ 26 | bindings/luabind.c 27 | 28 | MODULES=\ 29 | $(MOD)/module_bus.lua \ 30 | $(MOD)/module_custom.lua \ 31 | $(MOD)/module_events.lua \ 32 | $(MOD)/module_fifo.lua \ 33 | $(MOD)/module_uart.lua \ 34 | $(MOD)/module_pin.lua 35 | 36 | DEVICE=\ 37 | $(DEV)/device.lua 38 | 39 | CFLAGS:=-O3 -m32 -gdwarf-2 -fgnu89-inline -std=gnu99 -g3 -Wno-unused-variable -static-libgcc -static-libstdc++ -I../include -Imodules \ 40 | -I../externals/$(LUADIR)/src -D__VERSION=\"$(shell ../relgen.sh)\" 41 | 42 | SLIB_CFLAGS:=-Wl,--export-all-symbols,--enable-auto-import 43 | 44 | LDFLAGS:=-m32 ../externals/$(LUADIR)/src/liblua.a -lm -static-libgcc -static-libstdc++ 45 | 46 | OBJ=$(SRC:%.c=%.o) openvsm.res \ 47 | $(MOD)/module_bus.c.o $(MOD)/module_custom.c.o \ 48 | $(MOD)/module_events.c.o $(MOD)/module_pin.c.o \ 49 | $(MOD)/module_fifo.c.o $(MOD)/module_uart.c.o \ 50 | $(DEV)/device.c.o 51 | 52 | LOBJ:=$(MODULES:%.lua=%.mod) 53 | LOBJ+=$(DEVICE:%.lua=%.mod) 54 | 55 | all: modules $(OPENVSMLIB).dll 56 | 57 | %.mod: %.lua 58 | $(LUAC) -s -o $@ $< 59 | $(XXD) $@ > $@.c 60 | 61 | openvsm.res: 62 | $(WINRES) openvsm.rc --output-format=coff --target=pe-i386 -o openvsm.res 63 | 64 | $(DEV)/device.c.o: 65 | $(CC) -c -o $@ $(DEV)/device.mod.c $(CFLAGS) 66 | 67 | $(MOD)/module_bus.c.o: 68 | $(CC) -c -o $@ $(MOD)/module_bus.mod.c $(CFLAGS) 69 | 70 | $(MOD)/module_fifo.c.o: 71 | $(CC) -c -o $@ $(MOD)/module_fifo.mod.c $(CFLAGS) 72 | 73 | $(MOD)/module_custom.c.o: 74 | $(CC) -c -o $@ $(MOD)/module_custom.mod.c $(CFLAGS) 75 | 76 | $(MOD)/module_uart.c.o: 77 | $(CC) -c -o $@ $(MOD)/module_uart.mod.c $(CFLAGS) 78 | 79 | $(MOD)/module_pin.c.o: 80 | $(CC) -c -o $@ $(MOD)/module_pin.mod.c $(CFLAGS) 81 | 82 | $(MOD)/module_events.c.o: 83 | $(CC) -c -o $@ $(MOD)/module_events.mod.c $(CFLAGS) 84 | 85 | %.o: %.c 86 | $(CC) -c -o $@ $< $(CFLAGS) 87 | 88 | $(OPENVSMLIB).dll: $(OBJ) 89 | $(CC) -shared -o $@ $^ $(LDFLAGS) $(SLIB_CFLAGS) 90 | $(OBJCOPY) --only-keep-debug $(OPENVSMLIB).dll $(OPENVSMLIB).dwarf 91 | $(STRIP) -s $(OPENVSMLIB).dll 92 | $(OBJCOPY) --add-gnu-debuglink=$(OPENVSMLIB).dwarf $(OPENVSMLIB).dll 93 | 94 | modules: $(LOBJ) 95 | @echo "Lua modules compiled" 96 | 97 | SUBDIRS:= . modules device bindings ../externals/$(LUADIR)/src/ 98 | 99 | clean: 100 | rm -f $(OPENVSMLIB).* 101 | for dir in $(SUBDIRS); do \ 102 | rm -f $$dir/*.o; \ 103 | rm -f $$dir/*.res; \ 104 | rm -f $$dir/*.mod; \ 105 | rm -f $$dir/*.mod.c; \ 106 | done -------------------------------------------------------------------------------- /src/device/device.lua: -------------------------------------------------------------------------------- 1 | -- Here you can place you device code. 2 | -- It will be automatically compiled at build time 3 | -- Comment out this to use predefined script 4 | --[[ 5 | __USE_PRECOMPILED = 0xDEADC0DE 6 | 7 | --NAND gate placeholder script 8 | SAFE_MODE=true 9 | LOGIC_TYPE=TTL 10 | 11 | device_pins = 12 | { 13 | {name = "TX", on_time=100000, off_time=100000} 14 | } 15 | 16 | function device_simulate () 17 | Q:set(1-(A:get() * B:get())) 18 | end 19 | ]]-- -------------------------------------------------------------------------------- /src/lua_bus.c: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * @file lua_bus.c 4 | * @author Lavrentiy Ivanov (ookami@mail.ru) 5 | * @date 22.09.2014 6 | * @copyright Copyright 2015 Lavrentiy Ivanov. All rights reserved 7 | * @license This project is released under the GPL 2 license. 8 | * @brief Set of PIN object methods 9 | * 10 | */ 11 | 12 | #include 13 | 14 | /**********************************************************************************************/ /** 15 | * \fn int lua_set_bus ( lua_State* L ) 16 | * 17 | * \brief Lua set bus. 18 | * 19 | * \author Pugnator 20 | * \date 11/22/2015 21 | * 22 | * \param [in,out] L If non-null, the lua_State to process. 23 | * 24 | * \return An int. 25 | **/ 26 | 27 | int lua_set_bus(lua_State *L) 28 | { 29 | /// FIXME: add custom table-checking function, as Lua's lua_istable is a macro and can be used 30 | IDSIMMODEL *this = (IDSIMMODEL *)lua_get_model_obj(L); 31 | int byte = lua_tointeger(L, -1); 32 | lua_pop(this->luactx, 1); // Pop out the byte from the stack 33 | 34 | if (0 == lua_istable(L, -1)) 35 | { 36 | print_error(this, TEXT_NO_BUS_FOUND); 37 | return 0; 38 | } 39 | lua_len(this->luactx, -1); 40 | int32_t pin_number = lua_tointeger(this->luactx, -1); 41 | if (0 == pin_number) 42 | { 43 | WARNING(this, TEXT_BUS_HAS_NO_PINS); 44 | return 0; 45 | } 46 | #ifdef __DEBUG 47 | else 48 | { 49 | int maxval = pow(2, pin_number); 50 | if (byte >= maxval) 51 | { 52 | WARNING(this, TEXT_VALUE_WONT_FIT_BUS, byte, maxval - 1); 53 | } 54 | } 55 | #endif 56 | lua_pop(this->luactx, 1); // Pop out pin_number from the stack 57 | int bit_counter = 0; 58 | for (int i = 1; i <= pin_number; i++) 59 | { 60 | lua_rawgeti(this->luactx, -1, i); 61 | lua_getfield(this->luactx, -1, TEXT_PIN_FIELD); 62 | int pin = lua_tointeger(this->luactx, -1); 63 | set_pin_bool(this, this->device_pins[pin], byte >> bit_counter & 1); 64 | lua_pop(this->luactx, 1); // Pop the value 65 | lua_pop(this->luactx, 1); // Pop the pin object 66 | bit_counter++; 67 | } 68 | return 0; 69 | } 70 | 71 | /**********************************************************************************************/ /** 72 | * \fn int lua_get_bus ( lua_State* L ) 73 | * 74 | * \brief Lua get bus. 75 | * 76 | * \author Pugnator 77 | * \date 11/22/2015 78 | * 79 | * \param [in,out] L If non-null, the lua_State to process. 80 | * 81 | * \return An int. 82 | **/ 83 | 84 | int lua_get_bus(lua_State *L) 85 | { 86 | /// FIXME: add custom table-checking function, as Lua's lua_istable is a macro and can be used 87 | IDSIMMODEL *this = (IDSIMMODEL *)lua_get_model_obj(L); 88 | if (0 == lua_istable(L, 1)) 89 | { 90 | print_error(this, TEXT_NO_BUS_FOUND); 91 | } 92 | 93 | int bit_counter = 0; 94 | /**TODO: Add bus size check here. 32 or 64bit bus max */ 95 | int data = 0; 96 | lua_len(this->luactx, -1); 97 | int32_t pin_number = lua_tointeger(this->luactx, -1); 98 | if (0 == pin_number) 99 | { 100 | WARNING(this, TEXT_BUS_HAS_NO_PINS); 101 | return 0; 102 | } 103 | lua_pop(this->luactx, 1); // Pop out pin_number from the stack 104 | bool has_floats = false; 105 | for (int i = 1; i <= pin_number; i++) 106 | { 107 | lua_rawgeti(this->luactx, -1, i); 108 | lua_getfield(this->luactx, -1, TEXT_PIN_FIELD); 109 | int pin = lua_tointeger(this->luactx, -1); 110 | int bit = get_pin_bool(this->device_pins[pin]); 111 | lua_pop(this->luactx, 1); // Pop the value 112 | lua_pop(this->luactx, 1); // Pop the pin object 113 | if (-1 == bit) 114 | { 115 | // If pin is floating - set it to random value 116 | bit = xorshift(this) & 1; 117 | has_floats = true; 118 | } 119 | 120 | if (bit) 121 | { 122 | data |= (1 << bit_counter); 123 | } 124 | else 125 | { 126 | data &= ~(1 << bit_counter); 127 | } 128 | bit_counter++; 129 | } 130 | #ifdef __DEBUG 131 | if (has_floats) 132 | { 133 | WARNING(this, "Bus has floating pins"); 134 | } 135 | #endif 136 | lua_pushinteger(L, data); 137 | return 1; 138 | } 139 | -------------------------------------------------------------------------------- /src/lua_vsmobj.c: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * @file vsmobj.c 4 | * @author Lavrentiy Ivanov (ookami@mail.ru) 5 | * @date 22.09.2014 6 | * @copyright Copyright 2015 Lavrentiy Ivanov. All rights reserved 7 | * @license This project is released under the GPL 2 license. 8 | * 9 | */ 10 | 11 | #include 12 | 13 | void *lua_get_model_obj(lua_State *L) 14 | { 15 | lua_pushliteral(L, "__this"); 16 | lua_gettable(L, LUA_REGISTRYINDEX); 17 | void *this = lua_touserdata(L, -1); 18 | lua_pop(L, 1); 19 | return this; 20 | } 21 | -------------------------------------------------------------------------------- /src/modules/module_bus.lua: -------------------------------------------------------------------------------- 1 | --IC Bus object 2 | 3 | Bus = {} 4 | Bus.__index = Bus 5 | 6 | function Bus.new (pins) 7 | local _bus = {} 8 | setmetatable(_bus,Bus) 9 | _bus.pins = pins 10 | return _bus 11 | end 12 | 13 | function Bus:get () 14 | return get_bus(self.pins) 15 | end 16 | 17 | function Bus:set (val) 18 | set_bus(self.pins, val) 19 | end -------------------------------------------------------------------------------- /src/modules/module_custom.lua: -------------------------------------------------------------------------------- 1 | print = info -------------------------------------------------------------------------------- /src/modules/module_events.lua: -------------------------------------------------------------------------------- 1 | function eventsInit() 2 | --for k, v in pairs(device_pins) do info(_G[v.name]) end 3 | end 4 | -------------------------------------------------------------------------------- /src/modules/module_fifo.lua: -------------------------------------------------------------------------------- 1 | -- Stack Table 2 | -- Uses a table as stack, use :push(value) and
:pop() 3 | -- Lua 5.3 compatible 4 | 5 | -- GLOBAL 6 | fifo = {} 7 | fifo.__index = fifo 8 | 9 | setmetatable(fifo, { 10 | __call = function (cls, ...) 11 | return cls.new(...) 12 | end, 13 | }) 14 | 15 | -- Create a Table with stack functions 16 | function fifo.new() 17 | local self = setmetatable({}, fifo) 18 | self.stack = {} 19 | return self 20 | end 21 | 22 | 23 | -- push a value on to the stack 24 | function fifo:push(...) 25 | if ... then 26 | local targs = {...} 27 | -- add values at the END 28 | for _,v in ipairs(targs) do 29 | table.insert(self.stack, 1, v) 30 | end 31 | end 32 | end 33 | 34 | -- pop a value from the stack 35 | function fifo:pop(num) 36 | 37 | -- get num values from stack 38 | local num = num or 1 39 | 40 | -- return table 41 | local entries = {} 42 | 43 | -- get values into entries 44 | for i = 1, num do 45 | -- get last entry 46 | if #self.stack ~= 0 then 47 | table.insert(entries, self.stack[#self.stack]) 48 | -- remove last value 49 | table.remove(self.stack) 50 | else 51 | break 52 | end 53 | end 54 | -- return unpacked entries 55 | return table.unpack(entries) 56 | end 57 | 58 | -- get entries 59 | function fifo:getn() 60 | return #self.stack 61 | end 62 | 63 | -- list values 64 | function fifo:list() 65 | for i,v in pairs(self.stack) do 66 | info(i, v) 67 | end 68 | end 69 | -------------------------------------------------------------------------------- /src/modules/module_pin.lua: -------------------------------------------------------------------------------- 1 | --Here goes nothing 2 | function __pin_dummy() 3 | end 4 | -------------------------------------------------------------------------------- /src/modules/module_uart.lua: -------------------------------------------------------------------------------- 1 | -- UART implementation 2 | -- Lua 5.3 compatible 3 | 4 | UART_CLOCK_ID = 3955961 5 | 6 | Uart = {} 7 | Uart.__index = Uart 8 | 9 | setmetatable(Uart, { 10 | __call = function (cls, ...) 11 | return cls.new(...) 12 | end, 13 | }) 14 | 15 | function Uart.new(pin) 16 | local self = setmetatable({}, Uart) 17 | self.bits = 0 18 | self.data = 0 19 | self.go = 0 20 | self.tx = pin 21 | self.buf = fifo.new() 22 | return self 23 | end 24 | 25 | function Uart:send_string(str) 26 | for c in str:gmatch"." do 27 | self.buf:push(string.byte(c)) 28 | end 29 | end 30 | 31 | function Uart:send(time) 32 | if 0 == self.go then 33 | self.data = self.buf:pop() 34 | if nil == self.data then return end 35 | self.go = 1 36 | end 37 | 38 | if 0 == self.bits then 39 | self.tx:set(0) 40 | elseif 9 == self.bits then 41 | self.tx:set(1) 42 | else 43 | if 1 == bit32.extract(self.data, self.bits - 1) then 44 | self.tx:set(1) 45 | else 46 | self.tx:set(0) 47 | end 48 | end 49 | 50 | if 9 == self.bits then 51 | self.bits = 0 52 | self.go = 0 53 | set_callback(time + (150 * USEC), UART_CLOCK_ID) 54 | else 55 | set_callback(time + (104 * USEC), UART_CLOCK_ID) 56 | self.bits = self.bits + 1 57 | end 58 | end -------------------------------------------------------------------------------- /src/modules/modules.h: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * @file modules.h 4 | * @author Lavrentiy Ivanov (ookami@mail.ru) 5 | * @date 22.09.2014 6 | * @copyright Copyright 2014 Lavrentiy Ivanov. All rights reserved 7 | * @license This project is released under the BSD 2-Clause license. 8 | * 9 | */ 10 | 11 | #pragma once 12 | 13 | extern unsigned char module_bus_mod[]; 14 | extern unsigned long long module_bus_mod_len; 15 | 16 | extern unsigned char module_custom_mod[]; 17 | extern unsigned long long module_custom_mod_len; 18 | 19 | extern unsigned char module_events_mod[]; 20 | extern unsigned long long module_events_mod_len; 21 | 22 | extern unsigned char module_pin_mod[]; 23 | extern unsigned long long module_pin_mod_len; 24 | 25 | extern unsigned char module_fifo_mod[]; 26 | extern unsigned long long module_fifo_mod_len; 27 | 28 | extern unsigned char device_mod[]; 29 | extern unsigned long long device_mod_len; 30 | 31 | extern unsigned char module_uart_mod[]; 32 | extern unsigned long long module_uart_mod_len; -------------------------------------------------------------------------------- /src/openvsm.rc: -------------------------------------------------------------------------------- 1 | #include "../include/version.h" 2 | #include "windows.h" 3 | 1 VERSIONINFO 4 | FILEVERSION FILEVER 5 | PRODUCTVERSION PRODUCTVER 6 | FILEFLAGSMASK 0x17L 7 | #ifdef _DEBUG 8 | FILEFLAGS 0x1L 9 | #else 10 | FILEFLAGS 0x0L 11 | #endif 12 | FILEOS 0x4L 13 | FILETYPE 0x1L 14 | FILESUBTYPE 0x0L 15 | BEGIN 16 | BLOCK "StringFileInfo" 17 | BEGIN 18 | BLOCK "080904b0" 19 | BEGIN 20 | VALUE "Comments", "OpenVSM\0" 21 | VALUE "FileDescription", "OpenVSM Lua engine" 22 | VALUE "FileVersion", STRFILEVER 23 | VALUE "InternalName", "openvsm.dll" 24 | VALUE "LegalCopyright", "GPLv2" 25 | VALUE "ProductName", "OpenVSM" 26 | VALUE "ProductVersion", STRPRODUCTVER 27 | END 28 | END 29 | BLOCK "VarFileInfo" 30 | BEGIN 31 | VALUE "Translation", 0x809, 1200 32 | END 33 | END 34 | -------------------------------------------------------------------------------- /src/subsys/sound/main.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "SFML/Audio.h" 4 | 5 | int main() 6 | { 7 | sfMusic *buf = sfMusic_createFromFile("c:\\new.ogg"); 8 | if (NULL == buf) 9 | { 10 | puts("Failed"); 11 | } 12 | 13 | sfMusic_play(buf); 14 | getchar(); 15 | sfMusic_destroy(buf); 16 | return 0; 17 | } 18 | -------------------------------------------------------------------------------- /src/subsys/sound/sound.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pugnator/openvsm/c28a7a8210ea2fabc57951ce33cfb3b047d4348d/src/subsys/sound/sound.c -------------------------------------------------------------------------------- /src/utils.c: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * @file utils.c 4 | * @author Lavrentiy Ivanov (ookami@mail.ru) 5 | * @date 22.09.2014 6 | * @copyright Copyright 2015 Lavrentiy Ivanov. All rights reserved 7 | * @license This project is released under the GPL 2 license. 8 | * @brief Set of PIN object methods 9 | * 10 | */ 11 | 12 | #include 13 | 14 | /** 15 | * \fn unsigned rand256() 16 | * 17 | * \brief Random 256. 18 | * 19 | * \author Pugnator 20 | * \date 11/22/2015 21 | * 22 | * \return An unsigned. 23 | */ 24 | 25 | static uint32_t 26 | rand256() 27 | { 28 | static uint32_t const limit = RAND_MAX - RAND_MAX % 256; 29 | uint32_t result = rand(); 30 | while (result >= limit) 31 | { 32 | result = rand(); 33 | } 34 | return result % 256; 35 | } 36 | 37 | /** 38 | * \fn unsigned long long rand64bits() 39 | * 40 | * \brief Random 64bits. 41 | * 42 | * \author Pugnator 43 | * \date 11/22/2015 44 | * 45 | * \return A long. 46 | */ 47 | 48 | uint64_t 49 | rand64bits() 50 | { 51 | uint64_t results = 0ULL; 52 | for (int count = 8; count > 0; --count) 53 | { 54 | results = 256U * results + rand256(); 55 | } 56 | return results; 57 | } 58 | 59 | /** 60 | * \fn uint64_t xorshift ( IDSIMMODEL* this ) 61 | * 62 | * \brief Xorshifts the given this. 63 | * 64 | * \author Pugnator 65 | * \date 11/22/2015 66 | * 67 | * \param [in,out] this If non-null, this. 68 | * 69 | * \return An uint64_t. 70 | */ 71 | 72 | uint64_t 73 | xorshift(IDSIMMODEL *this) 74 | { 75 | uint64_t x = this->xorseed[0]; 76 | uint64_t const y = this->xorseed[1]; 77 | this->xorseed[0] = y; 78 | x ^= x << 23; // a 79 | x ^= x >> 17; // b 80 | x ^= y ^ (y >> 26); // c //-V537 81 | this->xorseed[1] = x; 82 | return x + y; 83 | } 84 | -------------------------------------------------------------------------------- /src/wincompat.c: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * @file wincompat.c 4 | * @author Lavrentiy Ivanov (ookami@mail.ru) 5 | * @date 22.09.2014 6 | * @copyright Copyright 2015 Lavrentiy Ivanov. All rights reserved 7 | * @license This project is released under the GPL 2 license. 8 | * 9 | */ 10 | 11 | #include 12 | 13 | /**********************************************************************************************/ /** 14 | * \fn int32_t vasprintf ( char** sptr, char* fmt, va_list argv ) 15 | * 16 | * \brief Vasprintfs. 17 | * 18 | * \author Pugnator 19 | * \date 11/22/2015 20 | * 21 | * \param [in,out] sptr If non-null, the sptr. 22 | * \param [in,out] fmt If non-null, describes the format to use. 23 | * \param argv The argv. 24 | * 25 | * \return An int32_t. 26 | **/ 27 | 28 | int32_t vasprintf(char **sptr, char *fmt, va_list argv) 29 | { 30 | int32_t wanted = vsnprintf(*sptr = NULL, 0, fmt, argv); 31 | if ((wanted > 0) && ((*sptr = malloc(1 + wanted)) != NULL)) 32 | return vsprintf(*sptr, fmt, argv); 33 | 34 | return wanted; 35 | } 36 | 37 | /**********************************************************************************************/ /** 38 | * \fn int32_t asprintf ( char** sptr, char* fmt, ... ) 39 | * 40 | * \brief Asprintfs. 41 | * 42 | * \author Pugnator 43 | * \date 11/22/2015 44 | * 45 | * \param [in,out] sptr If non-null, the sptr. 46 | * \param [in,out] fmt If non-null, describes the format to use. 47 | * \param ... Variable arguments providing additional information. 48 | * 49 | * \return An int32_t. 50 | **/ 51 | 52 | int32_t asprintf(char **sptr, char *fmt, ...) 53 | { 54 | int32_t retval; 55 | va_list argv; 56 | va_start(argv, fmt); 57 | retval = vasprintf(sptr, fmt, argv); 58 | va_end(argv); 59 | return retval; 60 | } 61 | --------------------------------------------------------------------------------